<template>
  <div class="page-container page-container-create">
    <!-- 面包屑 -->
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>营销中心</el-breadcrumb-item>
        <el-breadcrumb-item>优惠券</el-breadcrumb-item>
        <el-breadcrumb-item>编辑优惠券</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <p class="font22 mb20" v-if="promotionId && promotionId != '0'">编辑优惠券</p>
    <p class="font22 mb20" v-else>创建优惠券</p>

    <div class="stepset stepset1">
      <ul>
        <li :class="{ active: active >= 1 }">
          <span>1</span>
          <p>设置优惠券规则</p>
        </li>
        <!--
         <li :class="{'active':active>=2}"><span>2</span>
          <p>商家/店铺限制</p>
        </li>
             -->

        <li :class="{active:active>=3}"><span>2</span>
          <p>商品限制</p>
        </li>
        <li :class="{ active: active >= 4 }">
          <span>3</span>
          <p>触发场景</p>
        </li>
        <li :class="{ active: active >= 5 }">
          <span>4</span>
          <p>创建成功</p>
        </li>
      </ul>
    </div>

    <!-- 创建活动第一步 -->
    <div
      v-show="active == 1"
      class="content create_stepOne createSet create_stepAlso"
    >
      <el-form
        :inline="true"
        :model="dataForm"
        :rules="dataFormRules"
        ref="dataForm"
        label-width="140px"
      >
        <div>
          <div class="title">基本信息：</div>
          <div class="item">
            <el-row class="m_b30">
              <el-form-item label="优惠劵名称：" prop="promName" class="wid">
                <el-input
                  clearable
                  type="text"
                  v-model.trim="dataForm.promName"
                  placeholder="请输入3-60个字符之间"
                  size="mini"
                  class="input"
                />
              </el-form-item>
            </el-row>
            <el-row class="m_b30">
              <el-form-item label="优惠券简称：" prop="abbreviationName" class="wid">
                <el-input
                  clearable
                  type="text"
                  v-model.trim="dataForm.abbreviationName"
                  placeholder="请输入3-60个字符之间"
                  size="mini"
                  class="input"
                />
              </el-form-item>
            </el-row>
            <el-row class="m_b30">
              <el-form-item label="活动描述：" prop="chineseDesc" class="wid">
                <el-input
                  clearable
                  type="text"
                  v-model.trim="dataForm.chineseDesc"
                  placeholder="请输入3-60个字符之间"
                  size="mini"
                  class="input"
                />
              </el-form-item>
            </el-row>
            <el-row class="m_b30">
              <el-form-item
                label="活动日期："
                prop="activityTime"
                class="wid w450"
              >
                <el-date-picker
                  v-model="dataForm.activityTime"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  @change="activityTime"
                  :picker-options="timeCheck"
                  :size="size"
                ></el-date-picker>
              </el-form-item>
            </el-row>
            <el-row class="m_b30">
              <el-form-item label="优惠券搜索词：" prop="searchKeyword" class="wid">
                <el-input
                  clearable
                  type="text"
                  v-model.trim="dataForm.searchKeyword"
                  placeholder="多个搜索词可用数据逗号‘,’隔开"
                  size="mini"
                  class="input"
                />
              </el-form-item>
            </el-row>
          </div>
        </div>

        <div class="w100">
          <div class="title">活动规则：</div>
          <div class="item">
            <el-row class="m_b30 labelAlignment">
              <el-form-item
                label="金额抵扣类型："
                prop="amountDeductType"
                class="wid"
              >
                <el-radio-group
                  v-model="dataForm.amountDeductType"
                  @change="amountDeductTypeChange"
                >
                  <el-radio
                    class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                    label="0"
                    value="0"
                    border
                    >商品券</el-radio
                  >
                  <el-tooltip class="item mt7 mr40" effect="dark" placement="top">
                      <div slot="content">
                    　　商品券指商品满减券；<br/>
                    　　商品券的平台券与商户券可叠加使用，相同商品在同一个订单可以使用2张商品券；<br/>
                    　　平台券与平台券、商户券与商户券自身不能叠加；<br/>
                        商品券可与代金券、运费券一起叠加使用；
                      </div>
                      <span class="tipsInfo">!</span>
                  </el-tooltip>
                  <el-radio
                    class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                    label="1"
                    value="1"
                    border
                    >运费券</el-radio
                  >
                  <el-tooltip class="item mt7 mr40" effect="dark" placement="top">
                      <div slot="content">
                    　　运费券指运费无门槛直减券，一个订单同时只能使用1运费张；<br/>
                    　　运费券可与商品券、代金券一起叠加使用；
                      </div>
                      <span class="tipsInfo">!</span>
                    </el-tooltip>
                  <el-radio
                    class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                    label="2"
                    value="2"
                    border
                    >代金券</el-radio
                  >
                  <el-tooltip class="item mt7 mr40" effect="dark" placement="top">
                      <div slot="content">
                    　　代金券指商品无门槛直减券，一个订单同时只能使用1代金张；<br/>
                    　　代金券可与商品券、运费券一起叠加使用；
                      </div>
                      <span class="tipsInfo">!</span>
                    </el-tooltip>
                  <el-radio
                    class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                    label="3"
                    value="3"
                    border
                    >话费抵用券</el-radio
                  >
                </el-radio-group>
              </el-form-item>
            </el-row>

            <el-row class="m_b30 labelAlignment">
              <el-form-item label="优惠方式：" prop="couponMode" class="wid">
                <el-radio-group
                  v-model="dataForm.couponMode"
                  @change="changeCouponMode"
                >
                  <el-radio
                    class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                    label="0"
                    value="0"
                    border
                    >金额券</el-radio
                  >
                  <el-radio
                    class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                    label="1"
                    value="1"
                    v-if="dataForm.amountDeductType != '2'&&dataForm.amountDeductType != '3'"
                    border
                    >折扣券</el-radio
                  >
                </el-radio-group>
              </el-form-item>
            </el-row>

            <el-row class="m_b30">
              <template v-if="promotionMethod">
                <el-form-item
                  label="优惠券面值："
                  prop="couponAmount"
                  class="wid"
                >
                  <el-input
                    clearable
                    type="text"
                    maxlength="10"
                    v-model="dataForm.couponAmount"
                    placeholder="优惠券面值(元)"
                    class="width450"
                    @change="budgetChange()"
                    @blur="budgetChange()"
                  />
                </el-form-item>
                <span class="s1">元</span>
              </template>
              <template v-if="discountMethod">
                <el-form-item
                  label="优惠折扣："
                  prop="couponAmount"
                  class="wid"
                >
                  <el-input
                    clearable
                    type="text"
                    v-model="dataForm.couponAmount"
                    maxlength="10"
                    placeholder="优惠折扣"
                    class="width450"
                    @change="budgetChange()"
                    @blur="budgetChange()"
                  />
                </el-form-item>
                <span class="s1">折</span>
              </template>
            </el-row>
            <el-row class="m_b30" v-if="dataForm.amountDeductType == '0'">
              <el-form-item
                label="使用条件："
                prop="useTotalAmountLimit"
                class="wid"
              >
                <el-input
                  clearable
                  v-model="dataForm.useTotalAmountLimit"
                  maxlength="10"
                  auto-complete="off"
                  type="text"
                  :size="size"
                  class="width450"
                ></el-input>
              </el-form-item>
              <span class="s1">元</span>
            </el-row>
            <el-row>
              <el-form-item
                label="发行数量："
                class="wid activityDesc"
                prop="grantTotalNum"
                style="margin-bottom: 30px !important"
              >
                <el-input
                  clearable
                  type="text"
                  v-model="dataForm.grantTotalNum"
                  maxlength="10"
                  placeholder="发行总量(张)"
                  oninput="value=value.replace(/[^\d]/g,'')"
                  class="width450"
                  @change="budgetChange()"
                  @blur="budgetChange()"
                />
              </el-form-item>
              <span class="s1 font16 color333 mr10">张</span>
            </el-row>
            <el-row>
              <el-form-item
                label="活动费用预算："
                class="wid activityDesc"
                prop="budget"
                style="margin-bottom: 30px !important"
              >
                <el-input
                  clearable
                  type="text"
                  v-model="dataForm.budget"
                  maxlength="10"
                  placeholder="活动费用预算（元）"
                  oninput="value=value.replace(/[^\d]/g,'')"
                  class="width450"
                />
              </el-form-item>
              <span class="s1 font16 color333 mr10">元</span>
            </el-row>

            <el-row>
              <el-form-item
                label="预警比例："
                class="wid activityDesc"
                prop="warningNum"
                style="margin-bottom: 30px !important"
              >
                <el-input
                  clearable
                  type="text"
                  v-model="dataForm.warningNum"
                  maxlength="10"
                  placeholder="预警比例（%）"
                  oninput="value=value.replace(/[^\d]/g,'')"
                  class="width450"
                />
              </el-form-item>
              <span class="s1 font16 color333 mr10">%</span>
            </el-row>

            <el-row class="m_b30">
              <el-form-item
                label="使用时间设置："
                prop="couponUseTime"
                class="wid w450"
              >
                <el-date-picker
                  v-model="dataForm.couponUseTime"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  @change="start_time"
                  :picker-options="couponUseTimeCheck"
                  :size="size"
                  class="mr10"
                ></el-date-picker>
                <el-tooltip
                  class="item mt7"
                  effect="dark"
                  content="活动开始后，使用时间开始前，买家可以领取但是不能使用"
                  placement="right"
                >
                  <span class="tipsInfo">!</span>
                </el-tooltip>
              </el-form-item>
            </el-row>

            <el-row>
              <el-form-item label="领取限制：" class="wid">
                <div class="m_b30">
                  <el-form-item prop="idLimitNum">
                    <el-input
                      clearable
                      type="text"
                      v-model="dataForm.idLimitNum"
                      maxlength="10"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      placeholder="不填写表示不限制"
                      class="width450"
                    />
                  </el-form-item>
                  <span class="s1">张（每ID总共可以领取）</span>
                </div>

                <div class="m_b30">
                  <el-form-item prop="idLimitDayNum">
                    <el-input
                      clearable
                      type="text"
                      v-model="dataForm.idLimitDayNum"
                      maxlength="10"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      placeholder="不填写表示不限制"
                      class="width450"
                    />
                  </el-form-item>
                  <span class="s1">张（每ID每日可以领取）</span>
                </div>
              </el-form-item>
            </el-row>

            <!--<el-row class="ways labelAlignment">
              <el-form-item label="活动描述：" class="wid" prop="chineseDesc">
                <el-input
                  class="activityDesc"
                  clearable
                  v-model="dataForm.chineseDesc"
                  auto-complete="off"
                  type="textarea"
                  placeholder="最多输入100个字符"
                  :size="size"
                  maxlength="100"
                ></el-input>
              </el-form-item>
            </el-row>
            <el-row class="m_b60">
              <el-form-item label class="wid">
                <div class="desc color666">
                  注：非必填字段，不填将显示系统默认文案（会存在某些促销类型无系统默认文案）。自定义输入活动规则描述描述后将显示在前台商品详情页中，请慎重填写。
                </div>
              </el-form-item>
            </el-row>-->
          </div>
        </div>

        <div class="w100" v-if="deptType != 3">
          <div class="title">交易规则：</div>
          <div class="item">
            <el-row class="m_b30 ways labelAlignment">
              <el-form-item
                label="是否分摊："
                prop="costAllocationFlag"
                class="wid"
              >
                <el-row class="m_b52">
                  <el-radio-group
                    v-model="dataForm.costAllocationFlag"
                    prop="costAllocationFlag"
                  >
                    <el-radio
                      class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                      v-model="dataForm.costAllocationFlag"
                      label="1"
                      checked="true"
                      name="type"
                      value="1"
                      border
                      >是</el-radio
                    >
                    <el-radio
                      class="form-radio mr40 noMarginLeft radioAlignment w130 t_l"
                      v-model="dataForm.costAllocationFlag"
                      label="2"
                      name="type"
                      value="2"
                      border
                      >否</el-radio
                    >
                  </el-radio-group>
                </el-row>
                <el-row class="m_b60 ways labelAlignment">
                  <div v-if="dataForm.costAllocationFlag == '1'" class="rates">
                    <template v-if="dataForm.costAllocationFlag == '1'">
                      <span>运营平台比例：</span>
                      <el-form-item prop="parentAllocationScale">
                        <el-input
                          clearable
                          v-model.trim="dataForm.parentAllocationScale"
                          oninput="value=value.replace(/[^\d]/g,'')"
                          auto-complete="off"
                          maxlength="10"
                          type="text"
                          :size="size"
                          class="parentPlatformRatio"
                        ></el-input>
                      </el-form-item>
                      <span class="m_r16">%</span>
                    </template>
                    <template v-if="dataForm.costAllocationFlag == '1'">
                      <span>商家比例：</span>
                      <el-form-item label prop="merchantAllocationScale">
                        <el-input
                          clearable
                          v-model.trim="dataForm.merchantAllocationScale"
                          oninput="value=value.replace(/[^\d]/g,'')"
                          auto-complete="off"
                          maxlength="10"
                          type="text"
                          :size="size"
                          class="parentPlatformRatio"
                        ></el-input>
                      </el-form-item>
                      <span class="m_r16">%</span>
                    </template>
                  </div>
                </el-row>
              </el-form-item>
            </el-row>
          </div>
        </div>

        <div class="w100">
          <div class="title">参与条件：</div>
          <div class="item">
            <el-row class="m_b30 labelAlignment">
              <el-form-item
                label="新老用户："
                prop="selectUserType"
                class="wid t_r"
                label-width="140px"
              >
                <div class="flex">
                  <div>
                    <el-checkbox
                      class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10"
                      border
                      :indeterminate="userTypeIsIndeterminate"
                      v-model="userTypeCheckAll"
                      @change="handleCheckAllUserTypeChange"
                      >全选</el-checkbox
                    >
                  </div>
                  <div>
                    <el-checkbox-group
                      v-model="selectUserType"
                      @change="handleCheckedUserTypeChange"
                    >
                      <el-checkbox
                        :label="1"
                        :key="1"
                        class="mr40 el-checkBox-padding noMarginLeft w130 t_l"
                        border
                        >新用户</el-checkbox
                      >
                      <el-checkbox
                        :label="2"
                        :key="2"
                        class="el-checkBox-padding noMarginLeft w130 t_l"
                        border
                        >老用户</el-checkbox
                      >
                    </el-checkbox-group>
                  </div>
                </div>
              </el-form-item>
            </el-row>

            <el-row class="m_b52 labelAlignment">
              <el-form-item
                label="会员类型："
                prop="selectMemTypes"
                class="wid t_r"
                label-width="140px"
              >
                <div class="flex">
                  <div>
                    <el-checkbox
                      class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10"
                      border
                      :indeterminate="memTypeIsIndeterminate"
                      v-model="memTypeCheckAll"
                      @change="handleCheckAllMemTypeChange"
                      >全选</el-checkbox
                    >
                  </div>
                  <div>
                    <el-checkbox-group
                      v-model="selectMemTypes"
                      @change="handleCheckedMemTypeChange"
                    >
                      <el-checkbox
                        :label="1"
                        :key="1"
                        class="mr40 el-checkBox-padding noMarginLeft"
                        border
                        >普通会员</el-checkbox
                      >
                      <el-checkbox
                        :label="2"
                        :key="2"
                        class="el-checkBox-padding noMarginLeft"
                        border
                        >we2000</el-checkbox
                      >
                      <el-checkbox
                        :label="3"
                        :key="3"
                        class="el-checkBox-padding noMarginLeft"
                        border
                        >分期会员</el-checkbox
                      >
                    </el-checkbox-group>
                  </div>
                </div>
              </el-form-item>
            </el-row>

            <el-row class="m_b52 labelAlignment">
              <el-form-item
                label="渠道入口："
                prop="source"
                class="wid t_r"
                label-width="140px"
              >
                <div class="flex">
                  <div>
                    <el-checkbox
                      class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10"
                      border
                      :indeterminate="channelIdIsIndeterminate"
                      v-model="channelIdCheckAll"
                      @change="handleCheckAllChannelIdChange"
                    >全选</el-checkbox
                    >
                  </div>
                  <div>
                    <el-checkbox-group
                      v-model="channelId"
                      @change="handleCheckedChannelIdChange"
                    >
                      <el-checkbox
                        :label="1"
                        :key="1"
                        class="mr40 el-checkBox-padding noMarginLeft"
                        border
                      >企业微信</el-checkbox
                      >
                      <el-checkbox
                        :label="2"
                        :key="2"
                        class="el-checkBox-padding noMarginLeft"
                        border
                      >xxx</el-checkbox
                      >
                      <el-checkbox
                        :label="3"
                        :key="3"
                        class="el-checkBox-padding noMarginLeft"
                        border
                      >yyy</el-checkbox
                      >
                    </el-checkbox-group>
                  </div>
                </div>
              </el-form-item>
            </el-row>

            <el-row class="m_b30">
              <el-form-item label="使用说明：" prop="couponUseDesc" class="wid">
                <el-input
                  clearable
                  v-model="dataForm.couponUseDesc"
                  auto-complete="off"
                  type="textarea"
                  placeholder="请输入使用说明"
                  :size="size"
                  class="remarks h286"
                ></el-input>
                <br>
                <div style="margin-top: 13px;">
                  <span>将用于前端展示，
                    <el-popover
                      placement="bottom"
                      width="400"
                      trigger="click">
                      <img src="/static/images/coupon-shili.png" style="width:400px;" />
                      <el-link type="primary" slot="reference">查看示例</el-link>
                    </el-popover>
                  </span>
                </div>
              </el-form-item>
              
            </el-row>
          </div>
        </div>
      </el-form>
    </div>

    <!-- 创建活动第二步 -->
    <div
      v-show="active == 2"
      class="tab-container tab-container-noPadding createSet"
    >
      <el-tabs v-model="activeName" type="border-card">
        <el-tab-pane label="商家" name="1">
          <el-row class="search-button-fix t_r">
            <el-button
              class="searchButton"
              size="mini"
              @click="searchMerchantFlag = !searchMerchantFlag"
              icon="el-icon-search"
              >搜索</el-button
            >
            <el-button class="searchButton" @click="addMerchant"
              >添加商家</el-button
            >
            <el-button class="resetButton" @click="batchDeleteMerchant"
              >批量删除</el-button
            >
          </el-row>

          <el-row class="f_r mb30" v-if="searchMerchantFlag">
            <el-form
              :inline="true"
              :model="merchantStaticDataForm"
              class="demo-form-inline2"
              size="small"
              ref="merchantStaticDataForm"
            >
              <el-form-item label="商家编码：" prop="orgNumber" class="mr30">
                <el-input
                  v-model="merchantStaticDataForm.orgNumber"
                  placeholder="商家编码"
                  clearable
                  maxlength="80"
                ></el-input>
              </el-form-item>
              <el-form-item label="商家名称：" prop="merchantName">
                <el-input
                  v-model="merchantStaticDataForm.merchantName"
                  placeholder="商家名称"
                  clearable
                  maxlength="80"
                ></el-input>
              </el-form-item>
              <el-form-item label prop="mpName">
                <el-button
                  class="resetButton"
                  size="mini"
                  @click="skillQueryMerchant()"
                  >查询</el-button
                >
                <el-button
                  class="resetButton"
                  size="mini"
                  @click="resetMerchantSearch()"
                  >重置</el-button
                >
              </el-form-item>
            </el-form>
          </el-row>

          <div class="table-section">
            <el-table
              :data="merchantStaticTableData"
              :header-cell-style="tableHeaderColor"
              ref="multipleTable"
              style="width: 100%"
              :row-class-name="tableRowClassName"
              :size="size"
              @selection-change="selectMerchantChange"
            >
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column v-if="false" prop="merchantId"></el-table-column>
              <el-table-column
                prop="orgNumber"
                label="商家编码"
                sortable
                align="center"
              ></el-table-column>
              <el-table-column
                prop="name"
                label="商家名称"
                align="center"
              ></el-table-column>
              <el-table-column
                prop="merchantType"
                label="商家类型"
                align="center"
              >
                <template slot-scope="scope">
                  <span v-if="scope.row.merchantType == '1'">自营商家</span>
                  <span v-else-if="scope.row.merchantType == '2'"
                    >第三方商家</span
                  >
                </template>
              </el-table-column>
              <el-table-column label="操作" fixed="right" align="center">
                <template slot-scope="scope">
                  <el-button
                    :size="size"
                    type="text"
                    @click="handleDelete(scope.$index, scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div v-if="merchantStaticTableData.length > 0" class="t_r">
            <el-pagination
              @size-change="merchantSizeChange"
              @current-change="merchantCurrentChange"
              :current-page="merchantStaticDataForm.start"
              :page-sizes="[10]"
              :page-size="merchantStaticDataForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="merchantTotal"
            ></el-pagination>
          </div>
        </el-tab-pane>
        <el-tab-pane label="店铺" name="2">
          <el-row class="search-button-fix t_r">
            <el-button
              class="searchButton"
              size="mini"
              @click="searchStoreFlag = !searchStoreFlag"
              icon="el-icon-search"
              >搜索</el-button
            >
            <el-button class="searchButton" @click="addStore"
              >添加店铺</el-button
            >
            <el-button class="resetButton" @click="batchDeleteStore"
              >批量删除</el-button
            >
          </el-row>
          <el-row v-if="searchStoreFlag" class="f_r mb30">
            <el-form
              :inline="true"
              :model="storeStaticDataForm"
              ref="storeStaticDataForm"
              class="demo-form-inline2"
              size="small"
            >
              <el-form-item label="店铺编码：" prop="storecode" class="mr30">
                <el-input
                  v-model="storeStaticDataForm.storecode"
                  placeholder="店铺编码"
                  clearable
                  maxlength="80"
                ></el-input>
              </el-form-item>
              <el-form-item label="店铺名称：" prop="storename">
                <el-input
                  v-model="storeStaticDataForm.storename"
                  placeholder="店铺名称"
                  clearable
                  maxlength="80"
                ></el-input>
              </el-form-item>
              <el-form-item label prop="mpName">
                <el-button
                  class="resetButton"
                  size="mini"
                  @click="skillQueryStore()"
                  >查询</el-button
                >
                <el-button
                  class="resetButton"
                  size="mini"
                  @click="resetStaticStoreSearch()"
                  >重置</el-button
                >
              </el-form-item>
            </el-form>
          </el-row>

          <div class="table-section">
            <el-table
              :data="storeTableData"
              :header-cell-style="tableHeaderColor"
              ref="multipleTable"
              style="width: 100%"
              :row-class-name="tableRowClassName"
              :size="size"
              @selection-change="selectStoreChange"
            >
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column v-if="false" prop="storeId">
                <template slot-scope="scope">
                  <div :model="scope.row.id"></div>
                </template>
              </el-table-column>
              <el-table-column
                prop="storeCode"
                label="店铺编码"
                sortable
                align="center"
              ></el-table-column>
              <el-table-column
                prop="storeName"
                label="店铺名称"
                align="center"
              ></el-table-column>
              <el-table-column label="店铺类型" align="center">
                <template slot-scope="scope">
                  　{{ scope.row.storeType == "0" ? "自营店铺" : "入驻店铺" }}
                </template>
              </el-table-column>
              <!--<el-table-column
                prop="merchantName"
                label="所属商家"
                align="center"
              ></el-table-column>-->
              <el-table-column label="操作" fixed="right" align="center">
                <template slot-scope="scope">
                  <el-button
                    :size="size"
                    type="text"
                    @click="handleDeleteStore(scope.$index, scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div v-if="storeTableData.length > 0" class="t_r">
            <el-pagination
              @size-change="storeSizeChange"
              @current-change="storeCurrentChange"
              :current-page="storeStaticDataForm.start"
              :page-sizes="[10]"
              :page-size="storeStaticDataForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="storeTotal"
            ></el-pagination>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 创建活动第三步 -->
 <div v-show="active == 3" class="tab-container createSet active3">
      <div class="row-line-button">
        <el-button type="primary" plain size="mini" v-if="skuTotal <= 9999"
          >已选商品({{ skuTotal }})</el-button
        >
        <el-button type="primary" plain size="mini" v-else
          >已选商品(9999+)</el-button
        >
        <div>
          <el-form
            :inline="true"
            :model="goodsStaticDataForm"
            class="demo-form-inline2"
            size="small"
            ref="goodsStaticDataForm"
          >
            <el-form-item>
              <el-button
                class="searchButton"
                size="mini"
                @click="searchGoodsFlag = !searchGoodsFlag"
                icon="el-icon-search"
                >搜索</el-button
              >
            </el-form-item>
            <!-- <el-form-item>
              <el-button class="searchButton" @click="saveAllGoods"
                >添加全部商品</el-button
              >
            </el-form-item> -->
            <el-form-item>
              <el-button class="searchButton" @click="add">添加商品</el-button>
            </el-form-item>
            <el-form-item>
              <el-button class="resetButton" @click="batchDeleteProduct"
                >批量删除</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-row>
        <el-form
          :inline="true"
          :model="queryGoodsReuqest"
          ref="queryGoodsReuqest"
          class="rightForm demo-form-inline2"
          size="small"
        >
          <span v-if="searchGoodsFlag">
            <el-form-item label="商户：" prop="storeId" class="mb30">
              <template>
                <el-select
                  v-model="queryGoodsReuqest.storeId"
                  clearable
                  placeholder="全部"
                >
                  <el-option
                    v-for="item in storeTableData"
                    :key="item.id"
                    :label="item.storeName"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </template>
            </el-form-item>

            <el-form-item label="商品编码：" prop="goodsCode" class="mb30">
              <el-input
                v-model="queryGoodsReuqest.goodsCode"
                clearable
                placeholder="商品编码"
                maxlength="80"
              ></el-input>
            </el-form-item>
            <el-form-item label="商品名称：" prop="goodsName" class="mb30">
              <el-input
                v-model="queryGoodsReuqest.goodsName"
                clearable
                placeholder="商品名称"
                maxlength="80"
              ></el-input>
            </el-form-item>
            <el-form-item label="商品分类：" prop="goodsType" class="mb30">
              <el-input
                v-model="queryGoodsReuqest.goodsType"
                clearable
                placeholder="商品分类"
                maxlength="80"
              ></el-input>
            </el-form-item>
            <el-form-item label>
              <el-button
                class="resetButton"
                size="mini"
                @click="skillQueryGoods()"
                >查询</el-button
              >
              <el-button
                class="resetButton"
                size="mini"
                @click="resetStaticGoodsSearch()"
                >重置</el-button
              >
            </el-form-item>
          </span>
          <!-- <el-form-item>
              <el-button
                type="primary"
                size="mini"
                @click="searchGoodsFlag = !searchGoodsFlag"
                icon="el-icon-search"
              >搜索</el-button>
            </el-form-item> -->
        </el-form>
      </el-row>
      <div class="tableTree">
        <!--
        <el-table
          :data="productTableData"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          border
          default-expand-all
          row-key="goodsId"
          :size="size"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @selection-change="selectPorduct"
          class="tableStyle"
        >
          <el-table-column type="selection" width="55"  align="center"></el-table-column> -->
        <el-table
          :data="productTableData"
          row-key="id"
          default-expand-all
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          @selection-change="selectPorduct"
          style="width: 100%"
          class="tableStyle"
        >
          <!--<el-table-column align="left" width="30">
            <template slot="header" slot-scope="scope">
              <div class="isAllChecked" v-if="productTableData.length > 0">
                <el-checkbox
                  :indeterminate="isIndeterminateProductCheck"
                  v-model="isAllProductChecked"
                  @change="handleCheckedAllProductChange"
                ></el-checkbox>
              </div>
            </template>
          </el-table-column>-->
          <!--<el-table-column width="40">
            <template slot-scope="scope">
              <el-checkbox
                :indeterminate="scope.row.isIndeterminateCheck"
                v-model="scope.row.isCheck"
                @change="handleCheckedProductChange(scope.row, $event)"
              ></el-checkbox>
            </template>
          </el-table-column>-->
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            prop="goodsCode"
            label="商品编码"
            sortable
            align="left"
          ></el-table-column>
          <el-table-column
            prop="goodsName"
            label="商品名称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="goodsType"
            label="商品分类"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="reserveNum"
            label="库存"
            align="center"
          ></el-table-column>
         <el-table-column
            prop="storeName"
            label="所属商户"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="storeCode"
            label="商户Code"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="price"
            label="零售价（元"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="stockLimit"
            label="活动库存"
            align="center"
          >
            <template slot-scope="scope">
              <el-input
                type="text"
                v-model.number="scope.row.stockLimit"
                @blur="updateCouponLimit(scope.row)"
                placeholder="活动库存"
                style="width:120px;"
                :size="size"
                clearable maxlength="10"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="individualLimit"
            label="个人限购"
            align="center"
          >
            <template slot-scope="scope">
              <el-input
                type="text"
                v-model.number="scope.row.individualLimit"
                @blur="updateCouponLimit(scope.row)"
                placeholder="个人限购"
                style="width:120px;"
                :size="size"
                clearable maxlength="10"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="orderLimit"
            label="订单限购"
            align="center"
          >
            <template slot-scope="scope">
              <el-input
                type="text"
                v-model.number="scope.row.orderLimit"
                @blur="updateCouponLimit(scope.row)"
                placeholder="订单限购"
                style="width:120px;"
                :size="size"
                clearable maxlength="10"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" align="center">
            <template slot-scope="scope">
              <el-button
                :size="size"
                type="text"
                @click="deleteProduct(scope.$index, scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="productTableData.length > 0" class="t_r">
        <el-pagination
          @size-change="goodsSizeChange"
          @current-change="goodsCurrentChange"
          :current-page="goodsStaticDataForm.start"
          :page-sizes="[10]"
          :page-size="goodsStaticDataForm.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="goodsTotal"
        ></el-pagination>
      </div>
    </div> 





    <div v-show="active == 4" class="content createSet">
      <div>
        <el-form
          :model="triggerSceneForm"
          :rules="triggerSceneFormRules"
          ref="triggerSceneForm"
          class="t_l"
        >
          <el-form-item label="触发类型：" class="labelColor333 mb30">
            <el-radio
              border
              v-model="triggerSceneForm.triggerType"
              label="1"
              class="mr30"
              >页面领取</el-radio
            >
            <el-radio
              border
              v-model="triggerSceneForm.triggerType"
              label="2"
              class="mr30"
              >自动发放</el-radio
            >
            <el-radio
              border
              v-model="triggerSceneForm.triggerType"
              label="3"
              class="mr30"
              >任务发放</el-radio
            >
          </el-form-item>
          <div v-if="triggerSceneForm.triggerType == '3'">
            <el-form-item label="任务发放：" class="trigger labelColor333 mb30">
              <el-checkbox
                border
                v-model="triggerSceneForm.userRegistered"
                class="mr30"
                >注册</el-checkbox
              >
              <el-checkbox
                border
                v-model="triggerSceneForm.userDetail"
                class="mr30"
                >完善个人信息</el-checkbox
              >
              <el-checkbox border v-model="triggerSceneForm.sign" class="mr30"
                >签到</el-checkbox
              >
              <el-checkbox
                border
                v-model="triggerSceneForm.favorite"
                class="mr30"
                >收藏商户</el-checkbox
              >
              <el-checkbox v-model="triggerSceneForm.lottery" class="mr30" border>抽奖</el-checkbox>
            </el-form-item>
            <el-form-item>
              <div class="w100">
                <div class="flex mb30 ml80">
                  <el-tabs
                    v-model="triggerActiveName"
                    @tab-click="triggerActiveClick"
                  >
                    <el-tab-pane label="拼团" name="1"></el-tab-pane>
                    <el-tab-pane label="秒杀" name="2"></el-tab-pane>
                  </el-tabs>
                </div>
                <div class="w100 t_r mb20">
                  <el-button
                    class="searchButton"
                    :size="size"
                    @click="addTrigger"
                    >添加</el-button
                  >
                </div>
                <div class="table-section w100" v-if="triggerActiveName == '1'">
                  <el-table
                    :data="patchGrouponTableData"
                    :header-cell-style="{
                      color: '#FFF',
                      'background-color': '#409EFF',
                      'text-align': 'center',
                    }"
                    :highlight-current-row="true"
                    :max-height="1500"
                    :size="size"
                    style="width: 100%"
                  >
                    <el-table-column
                      prop="id"
                      label="ID"
                      align="center"
                      width="100"
                    ></el-table-column>
                    <el-table-column
                      prop="promName"
                      label="活动名称"
                      align="center"
                      width="200"
                    ></el-table-column>
                    <el-table-column
                      label="活动开始/结束时间"
                      align="center"
                      width="300"
                    >
                      <template slot-scope="scope"
                        >{{ scope.row.startTime }} -
                        {{ scope.row.endTime }}</template
                      >
                    </el-table-column>
                    <el-table-column label="操作" align="center">
                      <template slot-scope="scope">
                        <el-button
                          :size="size"
                          type="text"
                          @click="deleteTrigger(scope.$index, scope.row)"
                          >删除</el-button
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <div class="table-section" v-if="triggerActiveName == '2'">
                  <el-table
                    :data="skillTableData"
                    :header-cell-style="{
                      color: '#FFF',
                      'background-color': '#409EFF',
                      'text-align': 'center',
                    }"
                    :highlight-current-row="true"
                    :max-height="1500"
                    :size="size"
                    style="width: 100%"
                  >
                    <!-- <el-table-column
                              type="selection"
                              width="55">
                      </el-table-column>-->
                    <el-table-column
                      prop="id"
                      label="ID"
                      align="center"
                      width="100"
                    ></el-table-column>
                    <el-table-column
                      prop="promName"
                      label="活动名称"
                      align="center"
                      width="200"
                    ></el-table-column>
                    <el-table-column
                      label="活动开始/结束时间"
                      align="center"
                      width="300"
                    >
                      <template slot-scope="scope"
                        >{{ scope.row.startTime }} -
                        {{ scope.row.endTime }}</template
                      >
                    </el-table-column>
                    <el-table-column label="操作" align="center">
                      <template slot-scope="scope">
                        <el-button
                          :size="size"
                          type="text"
                          @click="deleteTrigger(scope.$index, scope.row)"
                          >删除</el-button
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="发放次数：" class="trigger w100 labelColor333">
              <div class="flex issueTime">
                <el-input
                  clearable
                  v-model="triggerSceneForm.triggerNum"
                  :size="size"
                  class="w310 mr10"
                ></el-input>
                <span class="s1 turnInlineBlock h32 lh32">次</span>
              </div>
            </el-form-item>
          </div>
          <!-- <el-form-item label="页面发放：" class="trigger"> -->
          <!-- <el-checkbox v-model="triggerSceneForm.pageTrigger">用户领取</el-checkbox> -->
          <!-- </el-form-item> -->
        </el-form>
      </div>
    </div>

    <div v-show="active == 5" class="tab-container tab-success createSet">
      <div class="titleInfo">
        <img src="/static/images/success.png" />
        <span class="font20">活动创建成功!</span>
      </div>
      <div class="step-button2">
        <el-button class="resetButton" @click="viewList"
          >查看优惠券列表</el-button
        >
        <template>
          <kt-button
            type="primary"
            :size="size"
            @click="shenheHuodong(0)"
            perms="market:seckill:submit"
            v-show="[11, 14, 9].includes(dataForm.status)"
            label="提交审核"
            class="searchButton"
          />

          <kt-button
            type="primary"
            :size="size"
            @click="shenheHuodong(1)"
            v-show="statusFormat(dataForm) == 12"
            perms="market:seckill:verify"
            label="审核"
            class="searchButton"
          />
        </template>
        <kt-button
          type="primary"
          :size="size"
          @click="templateDialogFormVisible = true"
          perms="market:coupon:addtemp"
          label="保存模板"
          class="searchButton"
        />
      </div>
    </div>
    <!-- 上下按钮部分 -->
    <div class="step-button" v-if="active < 5">
      <el-button
        type="primary"
        :plain="active != 1 && active != 5"
        :size="size"
        v-if="active != 1 && active != 5"
        @click="back"
        class="resetButton"
        >上一步</el-button
      >
      <el-button
        type="primary"
        v-if="active != 5"
        :size="size"
        @click="next"
        class="searchButton"
        >下一步</el-button>
    </div>

    <!-- 模板弹窗 -->
    <el-dialog
      title="保存模板"
      :visible.sync="templateDialogFormVisible"
      class="el-dialog-style"
    >
      <el-form :model="templateForm" label-width="130px">
        <el-form-item label="模板名称：">
          <el-input
            clearable
            v-model="templateForm.templateName"
            autocomplete="off"
            size="mini"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          class="cancelButton"
          @click="templateDialogFormVisible = false"
          size="mini"
          >取消</el-button
        >
        <el-button class="searchButton" @click="saveTemplate()" size="mini"
          >保存模板</el-button
        >
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt />
    </el-dialog>

    <el-dialog
      :visible.sync="dialogVisibleTwo"
      title="添加商品"
      :close-on-click-modal="false"
    >
      <div class="flex">
        <el-form
          :inline="true"
          class="demo-form-inline2"
          size="small"
          v-model="formInline"
          ref="formInline"
          :rules="formInlineRules"
          label-width="112px"
        >
          <el-form-item label="商品名称：" class="w178 mb30">
            <el-input
              clearable
              v-model="formInline.chineseName"
              placeholder="商品名称"
              maxlength="80"
            ></el-input>
          </el-form-item>
          <el-form-item label="商品编码：" prop="code" class="w178 mb30">
            <el-input
              v-model="formInline.code"
              auto-complete="off"
              clearable
              maxlength="80"
              placeholder="商品编码"
            ></el-input>
          </el-form-item>
          <el-form-item label="商品分类：" class="w178 mb30">
            <el-input
              clearable
              v-model="formInline.categoryName"
              placeholder="商品分类"
              maxlength="80"
            ></el-input>
          </el-form-item>
         <el-form-item
            label="所属商户："
            prop="storeName"
            class="w178 mb30"
          >
            <el-input
              v-model="formInline.storeName"
              auto-complete="off"
              clearable
              maxlength="80"
              placeholder="所属商户"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="商户Code："
            prop="storeCode"
            class="w178 mb30"
          >
            <el-input
              v-model="formInline.storeCode"
              auto-complete="off"
              clearable
              maxlength="80"
              placeholder="商户Code"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>

      <el-row class="t_r mb30">
        <el-button
          class="resetButton"
          icon="el-icon-refresh"
          @click="restProductForm"
          >重置</el-button
        >
        <el-button
          class="searchButton"
          icon="el-icon-search"
          @click="queryPageProductManagement"
          >搜索</el-button
        >
      </el-row>
      <div class="table-section">
        <el-table
          :data="tableDataTwo"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          :size="size"
          @selection-change="selectAddProductChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            prop="thirdSpuId"
            label="商品编码"
            sortable
            align="center"
          ></el-table-column>
          <el-table-column
            prop="goodsName"
            label="商品名称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="goodsCategory"
            label="商品分类"
            align="center"
          ></el-table-column>
         <el-table-column
            prop="storeName"
            label="所属商户"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="storeCode"
            label="商户Code"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="salePriceScope"
            label="原价（元）"
            align="center"
          ></el-table-column>
          <!-- <el-table-column prop="stock" label="库存" align="center"></el-table-column> -->
        </el-table>
      </div>

      <div class="chosenSelect">
        <span>已选择商品：{{ selectAddProduct.length }}</span>
        <div v-if="tableDataTwo.length > 0" class="t_r">
          <el-pagination
            @size-change="producthandleSizeChange"
            @current-change="producthandleCurrentChange"
            :current-page="formInline.start"
            :page-sizes="[10]"
            :page-size="formInline.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="productListTotal"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          class="cancelButton"
          @click="dialogVisibleTwo = false"
          size="mini"
          >取消</el-button
        >
        <el-button class="searchButton" @click="addProductChange" size="mini"
          >确定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      title="审核"
      class="el-dialog-style"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
    >
      <el-form :model="form" ref="form" :rules="formRules">
        <el-form-item class="textarea" prop="checkRemark">
          <el-input
            clearable
            v-model="form.checkRemark"
            autocomplete="off"
            placeholder="请输入审核意见"
            type="textarea"
            rows="6"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          plain
          @click="reviewDialog(4)"
          size="mini"
          class="cancelButton"
          >不通过</el-button
        >
        <el-button
          type="primary"
          @click="reviewDialog(11)"
          size="mini"
          class="searchButton"
          >通过</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="dialogVisibleMerchant"
      title="添加商家"
      :close-on-click-modal="false"
    >
      <div class="flex">
        <el-form
          :inline="true"
          size="small"
          v-model="merchantDataForm"
          ref="merchantDataForm"
          :rules="merchantDataFormRules"
        >
          <el-form-item label="商家名称：">
            <el-input
              clearable
              v-model="merchantDataForm.name"
              placeholder="商家名称"
              class="w178"
              maxlength="80"
            ></el-input>
          </el-form-item>
          <el-form-item label="商家编码：">
            <el-input
              clearable
              v-model="merchantDataForm.orgNumber"
              placeholder="商家编码"
              class="w178"
              maxlength="80"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="商家类型："
            prop="merchantType"
            class="w178 mb30"
          >
            <el-select
              v-model="merchantDataForm.merchantType"
              placeholder="全部"
              clearable
            >
              <el-option label="自营商家" value="1"></el-option>
              <el-option label="第三方商户" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-row class="t_r mb30 w100">
          <el-button
            class="resetButton"
            icon="el-icon-refresh"
            @click="restMerchantForm"
            >重置</el-button
          >
          <el-button
            class="searchButton"
            icon="el-icon-search"
            @click="queryPageMerchantManagement"
            >搜索</el-button
          >
        </el-row>
      </div>

      <div class="table-section">
        <el-table
          :data="merchantTableData"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          :size="size"
          @selection-change="addMerchantChangeSelect"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            prop="orgNumber"
            label="商家编码"
            sortable
            align="center"
          ></el-table-column>
          <el-table-column
            prop="name"
            label="商家名称"
            align="center"
          ></el-table-column>
          <el-table-column prop="merchantType" label="商家类型" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.merchantType == '1'">自营商家</span>
              <span v-else-if="scope.row.merchantType == '2'">第三方商家</span>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="chosenSelect">
        <span>已选择商家：{{ addMerchantSelect.length }}</span>
        <div v-if="merchantTableData.length > 0" class="t_r">
          <el-pagination
            @size-change="merchanthandleSizeChange"
            @current-change="merchanthandleCurrentChange"
            :current-page="merchantDataForm.start"
            :page-sizes="[10]"
            :page-size="merchantDataForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="merchantListTotal"
          ></el-pagination>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          plain
          @click="dialogVisibleMerchant = false"
          size="mini"
          class="cancelButton"
          >取消</el-button
        >
        <el-button
          type="primary"
          @click="addMerchantChange"
          size="mini"
          class="searchButton"
          >确定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="dialogVisibleStore"
      title="添加店铺"
      :close-on-click-modal="false"
    >
      <!-- <el-row class="search-button-fix t_r"> -->
      <el-form
        :inline="true"
        class="demo-form-inline2"
        size="small"
        v-model="storeDataForm"
        ref="storeDataForm"
        :rules="storeDataFormRules"
      >
        <el-form-item label="店铺名称：" class="w178 mb30">
          <el-input
            clearable
            v-model="storeDataForm.storeName"
            placeholder="店铺名称"
            maxlength="80"
          ></el-input>
        </el-form-item>
        <el-form-item label="店铺编码：" class="w178">
          <el-input
            clearable
            v-model="storeDataForm.storeCode"
            placeholder="店铺编码"
            maxlength="80"
          ></el-input>
        </el-form-item>
        <!--<el-form-item label="所属商家名称：" prop="merchantName" class="w178">
          <el-input
            v-model="storeDataForm.merchantName"
            maxlength="80"
            placeholder="所属商家名称"
            size="mini"
            clearable
          ></el-input>
        </el-form-item>-->
        <el-form-item label="店铺类型：" prop="storeType" class="w178">
          <el-select
            v-model="storeDataForm.storeType"
            placeholder="全部"
            size="mini"
            clearable
          >
            <el-option label="自营店铺" value="0"></el-option>
            <el-option label="入驻店铺" value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="t_r mb30 w100">
        <!-- <el-form-item> -->
        <el-button
          class="resetButton"
          icon="el-icon-refresh"
          @click="restStoreForm('storeDataForm')"
          >重置</el-button
        >
        <el-button
          class="searchButton"
          icon="el-icon-search"
          @click="queryPageStoreList"
          >搜索</el-button
        >

        <!-- </el-form-item> -->
      </div>
      <!-- </el-row> -->

      <div class="table-section">
        <el-table
          :data="storeAddTableData"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          :size="size"
          @selection-change="addStoreChangeSelect"
        >
          <!-- <el-table-column prop="pictureUrl" label="主图" showImg="true"  align="center">

<template slot-scope="scope">

  　<img :src="scope.row.pictureUrl" width="30" height="30"/>

</template>
          </el-table-column>-->
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            prop="storeCode"
            label="店铺编码"
            align="center"
            width="300"
          ></el-table-column>
          <el-table-column
            prop="storeName"
            label="店铺名称"
            align="center"
          ></el-table-column>
          <el-table-column label="店铺类型" align="center">
            <template slot-scope="scope">
              　{{ scope.row.storeType == "0" ? "自营店铺" : "入驻店铺" }}
            </template>
          </el-table-column>
         <!-- <el-table-column
            prop="merchantName"
            label="所属商家"
            align="center"
          ></el-table-column>-->
        </el-table>
      </div>

      <div class="chosenSelect">
        <span>已选择店铺：{{ addStoreSelect.length }}</span>
        <div v-if="storeAddTableData.length > 0" class="t_r">
          <el-pagination
            @size-change="storehandleSizeChange"
            @current-change="storehandleCurrentChange"
            :current-page="storeDataForm.start"
            :page-sizes="[10]"
            :page-size="storeDataForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="storeListTotal"
          ></el-pagination>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          class="cancelButton"
          @click="dialogVisibleStore = false"
          size="mini"
          >取消</el-button
        >
        <el-button class="searchButton" @click="addStoreChange" size="mini"
          >确定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="triggerVisible"
      title="添加活动"
      :close-on-click-modal="false"
    >
      <div class="flex">
        <el-form
          :inline="true"
          size="small"
          :model="triggerDataForm"
          ref="triggerDataForm"
          :rules="triggerDataFormRules"
        >
          <el-form-item label="ID：" prop="id">
            <el-input
              clearable
              v-model="triggerDataForm.id"
              placeholder="ID"
              maxlength="80"
            ></el-input>
          </el-form-item>
          <el-form-item label="名称：" prop="promName">
            <el-input
              clearable
              v-model="triggerDataForm.promName"
              placeholder="名称"
              maxlength="80"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-row class="mb30 t_r">
          <el-button
            class="resetButton"
            icon="el-icon-refresh"
            @click="restForm()"
            >重置</el-button
          >
          <el-button
            class="searchButton"
            icon="el-icon-search"
            @click="triggerhandleCurrentChange(1)"
            >搜索</el-button
          >
        </el-row>
      </div>

      <div class="table-section">
        <el-table
          :data="triggerAddTableData"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          :row-class-name="tableRowClassName"
          :size="size"
          @selection-change="addTriggerChangeSelect"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            prop="id"
            label="活动ID"
            sortable
            align="center"
            width="200"
          ></el-table-column>
          <el-table-column
            prop="promName"
            label="活动名称"
            align="center"
            width="200"
          ></el-table-column>
          <el-table-column label="活动开始/结束时z间" align="center">
            <template slot-scope="scope"
              >{{ scope.row.startTime }} - {{ scope.row.endTime }}</template
            >
          </el-table-column>
        </el-table>
      </div>
      <div class="chosenSelect">
        <span>已选择数量:{{ triggerSelectData.length }}</span>
        <div v-if="triggerAddTableData.length > 0" class="t_r">
          <el-pagination
            @size-change="triggerhandleSizeChange"
            @current-change="triggerhandleCurrentChange"
            :current-page="triggerDataForm.start"
            :page-sizes="[10]"
            :page-size="triggerDataForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="triggerListTotal"
          ></el-pagination>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          class="cancelButton"
          plain
          @click="triggerVisible = false"
          size="mini"
          >取消</el-button
        >
        <el-button class="searchButton" @click="addTriggerChange" size="mini"
          >确定</el-button
        >
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { formatDate } from "@/utils/datetime";
import KtButton from "@/views/Core/KtButton";
import {
  singleFrontPromTypesRadio,
  chanelCodesRadio,
  proPlatformRadio,
  proUserTypeRadio,
  proMemberTypeRadio,
  proMemberLevelRadio,
} from "@/market/dict/marketDict";

import {
  getAllRow,
  changeChild,
  changeParent,
  reloadAllCheckedStatus,
} from "@/assets/js/tableTree.js";
export default {
  props: {
    type: {
      type: String,
      default: "0",
    },
    temId: {
      type: String,
      default: "0",
    },
  },
  components: {
    KtButton,
  },
  data() {
    let this_ = this;
    var checkNumber = (rule, value, callback) => {
      if (value === "") {
        return callback();
      }
      const r = /^\+?[1-9][0-9]*$/; // 正整数
      if (!r.test(value)) {
        return callback(new Error("请输入数字"));
      }
      return callback();
    };

    var isNumber = (rule, value, callback) => {
      if (value === "") {
        return callback();
      } //这是用来判断如果不是必须输入的，则直接跳出
      const r = /^\+?[1-9][0-9]*$/; // 正整数
      // 如果判断不符合正则，则不是正整数不能提交
      if (!r.test(value)) {
        return callback(new Error("必须为正整数"));
      } else {
        // if (
        //   this.filters.parentAllocationScale != undefined &&
        //   this.filters.merchantAllocationScale != undefined &&
        // ) {
        let countScale =
          Number(this_.dataForm.parentAllocationScale | 0) +
          Number(this_.dataForm.merchantAllocationScale | 0);
        if (countScale != 100) {
          return callback(new Error("加起来必须等于100%"));
        } else {
          this_.$refs.dataForm.clearValidate("merchantAllocationScale");
          this_.$refs.dataForm.clearValidate("parentAllocationScale");
          return callback();
        }
        // }
        // return callback();
      }
    };
    var checkParentAllocationScale = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入母平台分摊比例"));
      } else if (!/^[1-9][0-9]*([.][0-9]{1,2})?$/.test(value)) {
        //分摊比例为整数或两位小数
        callback(new Error("母平台分摊比例格式错误"));
      } else {
        callback();
      }
    };
    var checkMerchantAllocationScale = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入商家分摊比例"));
      } else if (!/^[1-9][0-9]*([.][0-9]{1,2})?$/.test(value)) {
        //分摊比例为整数或两位小数
        callback(new Error("商家分摊比例格式错误"));
      } else {
        callback();
      }
    };
    var checkAmount = (rule, value, callback) => {
      var r = /^\d+\.?\d{0,2}$/; // 2位小数
      // 如果判断不符合正则，则不是正整数不能提交
      if (!r.test(value)) {
        return callback(new Error("请输入数字(支持2位小数)"));
      }
      return callback();
    };
    var checkPositiveInteger = (rule, value, callback) => {
      var r1 = /^\+?[1-9][0-9]*$/; // 正整数
      if (!value) {
        return callback();
      } else if (!r1.test(value)) {
        return callback(new Error("必须为正整数"));
      }
      return callback();
    };
    // 校验预警比例
    var checkWaringNum = (rule, value, callback) => {
      if(value && Number(value) > 100){
        return callback(new Error("必须小于等于100%"));
      }else{
        return callback();
      }
    };
    /**
     * 校验会员等级
     */
    var checkMemLevel = (rule, value, callback) => {
      //查看每个子平台是否都选中了
      let memberGradeList = this.memberGradeList;
      if (memberGradeList == null || memberGradeList.length < 1) {
        return callback(new Error("会员等级不能为空"));
      }
      let flag = false;
      for (var i = 0; i < memberGradeList.length; i++) {
        if (
          (memberGradeList[i].levelSelectList == null ||
            memberGradeList[i].levelSelectList.length < 1) &&
          !memberGradeList[i].checkAll
        ) {
          flag = true;
          break;
        }
      }
      if (flag) {
        return callback(new Error("每个平台必须选中一个会员等级"));
      }
      return callback();
    };

    /**
     * 会员类型
     */
    var checkMemType = (rule, value, callback) => {
      if (this.selectMemTypes == null || this.selectMemTypes.length < 1) {
        return callback(new Error("请选择会员类型"));
      }

      return callback();
    };

    /**
     * 新老用户
     */
    var checkUserType = (rule, value, callback) => {
      if (this.selectUserType == null || this.selectUserType.length < 1) {
        return callback(new Error("请选择新老用户"));
      }

      return callback();
    };

    return {
      channelOption: [],
      formInlineRules: {
        // goodsName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // goodsCategory: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      merchantDataFormRules: {
        // name: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // orgNumber: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      storeDataFormRules: {
        // storeName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // storeCode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      promotionMethod: true,
      discountMethod: false,
      // 活动时间校验
      timeCheck: {
        disabledDate: (time) => {
          if (this.promotionStartEndTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() > new Date(this.promotionStartEndTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },
      
      // 活动时间校验
      couponUseTimeCheck: {
        disabledDate: (time) => {
          //
          // if (this.dataForm.activityTime.length <= 0) {
          return time.getTime() < Date.now() - 8.64e7;
          // } else {
          //
          // return time.getTime() > new Date(this.dataForm.startTime).getTime() && time.getTime() < new Date(this.dataForm.endTime).getTime();
          // return time.getTime() <= new Date(this.dataForm.startTime).getTime() && time.getTime() >= new Date(this.dataForm.endTime).getTime() ;
          //
          // }
        },
        onPick: (maxDate, minDate) => {},
      },
      templateDialogFormVisible: false, //模板弹窗
      templateForm: {}, //模板model
      formLabelWidth: "120px",
      dialogFormVisible: false,
      form: {},
      row: {},
      templateId: 0,
      couponId: "0",
      proActiveName: "first",
      shenhe: 0,
      productListloading: true,
      selectedOptions: [],
      formInline: {
        categoryName: "",
        chineseName: "",
        code:"",
        storeCode:"",
        storeName:"",
        start: 1,
        limit: 10,
      },
      tabsIndex: "first",
      tableData: [],
      tableDataTwo: [],
      dialogImageUrl: "",
      dialogVisible: false,
      dialogVisibleTwo: false,
      size: "mini",
      active: 0,
      isIndeterminate2: true,
      proUserTypeRadios: proUserTypeRadio,
      checkAll2: true,
      dataForm: {
        costAllocationFlag: "1", //是否分摊
        storeCode: "0", //店铺区域
        userCode: "0", //用户区域
        couponType: "0", //优惠券类型
        amountDeductType: "0", //金额抵扣类型
        couponMode: "0", //优惠方式
        limitOfAction: "0", //作用限制
        overlayFlag: "1", //是否叠加
        channelIds: [], //渠道Ids
        promName: "",
        couponAmount: null,
        couponUseDesc: "",
        // grantType:"0",
        idLimitNum: 1,
        idLimitDayNum: 1,
        proUserType: "0",
        costAllocation: "",
        proportion: "",
        grantTotalNum: null,
        budget:null,
        activityStartTime: "",
        activityEndTime: "",
        couponUseTime: [],
        couponUseStartTime: "",
        couponUseEndTime: "",
        useTotalAmountLimit: "",
        activityTime: [],
        grantType: "0",
        useChannel: [],
        frontPromType: "1100",
        promType: "11",
        parcelsFlag: "-1",
        searchKeyword:"",

      },
      dataFormRules: {
        costAllocationFlag: [
          {
            required: true,
            message: "请选择是否分摊",
            trigger: "change",
          },
        ],
        searchKeyword:[
          {
            required: true,
            message: "请输入优惠券搜索词",
            trigger: "blur",
          },
        ],
        parentAllocationScale: [
          {
            required: true,
            validator: isNumber,
            trigger: "blur",
          },
          {
            required: true,
            validator: isNumber,
            trigger: "change",
          },
        ],
        merchantAllocationScale: [
          {
            required: true,
            validator: isNumber,
            trigger: "blur",
          },
          {
            required: true,
            validator: isNumber,
            trigger: "change",
          },
        ],
        channelIds: [
          {
            required: true,
            message: "请选择使用渠道",
            trigger: "checked",
          },
        ],
        limitOfAction: [
          {
            required: true,
            message: "请选择作用限制",
            trigger: "change",
          },
        ],
        overlayFlag: [
          {
            required: true,
            message: "请选择是否叠加",
            trigger: "change",
          },
        ],
        abbreviationName:[
            {
                required: true,
                message: "请输入优惠券简称",
                trigger: "blur",
            }
        ],

        selectUserType: [
          {
            required: true,
            validator: checkUserType,
            trigger: "change",
          },
        ],

        promName: [
          {
            required: true,
            message: "请输入优惠券名称",
            trigger: "blur",
          },
          {
            min: 3,
            max: 60,
            message: "长度在 3 到 60 个字符",
            trigger: "blur",
          },
        ],
        couponType: [
          {
            required: true,
            message: "请输入优惠券种类",
            trigger: "blur",
          },
        ],
        amountDeductType: [
          {
            required: true,
            message: "请输入金额抵扣类型",
            trigger: "blur",
          },
        ],
        couponMode: [
          {
            required: true,
            message: "请输入优惠方式",
            trigger: "blur",
          },
        ],
        couponAmount: [
          {
            required: true,
            validator: checkAmount,
            trigger: "blur",
          },
        ],
        budget: [
          {
            required: true,
            validator: checkAmount,
            trigger: "blur",
          },
          {
            required: true,
            validator: checkAmount,
            trigger: "change",
          },
        ],
        warningNum: [
          { required: false, validator:checkWaringNum, trigger: "blur" },
          { required: false, validator:checkWaringNum, trigger: "change" }
        ],
        grantTotalNum: [
          {
            required: true,
            validator: checkPositiveInteger,
            trigger: "blur",
          },
        ],
        idLimitNum: [
          {
            required: false,
            validator: checkPositiveInteger,
            trigger: "blur",
          },
        ],
        idLimitDayNum: [
          {
            required: false,
            validator: checkPositiveInteger,
            trigger: "blur",
          },
        ],
        activityTime: [
          {
            required: true,
            message: "请输入券活动日期",
            trigger: "blur",
          },
        ],
        chineseDesc: [
          {
            required: true,
            message: "请输入活动描述",
            trigger: "blur",
          },
        ],
        couponUseTime: [
          {
            required: true,
            message: "请输入使用时间设置",
            trigger: "blur",
          },
        ],
        useTotalAmountLimit: [
          {
            required: true,
            validator: checkAmount,
            trigger: "blur",
          },
        ],
        costAllocation: [
          {
            required: true,
            message: "请选择是否成本分摊",
            trigger: "change",
          },
        ],

        // levelSelectList: [{ required: true , validator: checkMemLevel, trigger: "blur"}] ,
        selectMemTypes: [
          {
            required: true,
            validator: checkMemType,
            trigger: "change",
          },
        ],
      },

      triggerDataFormRules: {
        id: [
          {
            validator: checkNumber,
            trigger: "blur",
          },
        ],
      },
      //渠道List
      channelList: [],
      channlProps: {
        label: "childName",
      },
      //添加商家
      activeName: "1",
      merchantStaticTableData: [],
      dialogVisibleMerchant: false,
      merchantTableData: [],
      merchantListTotal: 0,
      productListloading: false,
      multipleMerchantSelection: [],
      merchantDataForm: {
        start: 1,
        limit: 10,
      },
      addMerchantSelect: [],

      //添加店铺
      storeTableData: [],
      dialogVisibleStore: false,
      multipleStoreSelection: [],
      storeDataForm: {
        start: 1,
        limit: 10,
      },
      storeAddTableData: [],
      addStoreSelect: [],
      storeListTotal: 0,

      //商品
      selectAddProduct: [],
      productTableData: [],
      productSelectFlag: [],
      proActiveName: "1",
      //触发场景
      triggerSceneForm: {
        triggerType: "1",
        userReceive: true,
        pageTrigger: true,
        userRegistered: true,
        userDetail: true,
        sign: true,
        favorite: true,
        triggerNum: 1,
      },
      triggerSceneFormRules: {},
      //限制
      patchGrouponTableData: [], //拼团静态列表
      skillTableData: [], //秒杀静态列表
      triggerActiveName: "1",
      triggerVisible: false,
      triggerDataForm: {
        start: 1,
        limit: 10,
        promName: "",
        id: "",
      },
      triggerSelectData: [],
      triggerAddTableData: [],
      triggerListTotal: 0,

      //活动ID
      promotionId:
        this.$route.params.promotionId == null
          ? "0"
          : this.$route.params.promotionId,
      deptType: localStorage.getItem("deptType"), //当前登录用户所属组织类型
      //商家页分页
      merchantStaticDataForm: {
        start: 1,
        limit: 10,
        merchantName: null,
        orgNumber: null,
      },
      merchantTotal: 0,

      //商家页分页
      storeStaticDataForm: {
        start: 1,
        limit: 10,
        storename: null,
        storecode: null,
      },
      storeTotal: 0,
      //商品也分页查询
      goodsTotal: 0,
      goodsStaticDataForm: {
        start: 1,
        limit: 10,
      },
      skuTotal: 0, //已选择sku数量

      searchMerchantFlag: false,
      searchStoreFlag: false,

      isAllProductChecked: false, //全选
      isIndeterminateProductCheck: false, //全选 checkbox 的不确定状态
      allProductData: [], //全选 操作数据
      //商品搜索
      queryGoodsReuqest: {
        goodsType: null,
        goodsName: null,
        goodsCode: null,
        storeId: null,
      },
      searchGoodsFlag: false,

      //会员等级 会员类型
      memberGradeList: [],
      reloadMemLevel: true,

      //会员类型
      memTypeCheckAll: true,
      selectMemTypes: [1, 2 , 3],
      channelId:[1,2,3],
      channelIdCheckAll:true,
      memTypeIsIndeterminate: false,
      channelIdIsIndeterminate:false,

      formRules: {
        checkRemark: [
          {
            required: true,
            message: "审核意见不能为空",
            trigger: "blur",
          },
        ],
      },

      userTypeCheckAll: true,
      selectUserType: [1, 2],
      userTypeIsIndeterminate: false,
    };
  },
  methods: {
    queryChannelListOther: function () {
      var this_ = this;
      this.utils.request.queryChannelListOther({}, function (res) {
        if (res.code == "0000") {
          this_.channelOption = res.data;
        }
      });
    },
    //新老用户
    handleCheckAllUserTypeChange(val) {
      this.selectUserType = val ? [1, 2] : [];
      this.userTypeIsIndeterminate = false;
    },
    handleCheckedUserTypeChange(value) {
      let checkedCount = value.length;
      this.userTypeCheckAll = checkedCount === 2;
      this.userTypeIsIndeterminate = checkedCount > 0 && checkedCount < 2;
    },
    /**
     * 状态格式化
     */
    statusFormat(row) {
      if (
        row.status == 1 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //待提交
        return 11;
      } else if (
        row.status == 2 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //待审核
        return 12;
      } else if (
        row.status == 11 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //未开始
        return 13;
      } else if (
        row.status == 4 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //审核未通过
        return 14;
      } else if (
        row.status == 11 &&
        new Date().getTime() >= new Date(row.startTime).getTime() &&
        new Date().getTime() <= new Date(row.endTime).getTime()
      ) {
        //进行中
        return 15;
      } else if (
        (row.status == 1 || row.status == 2 || row.status == 4) &&
        new Date().getTime() > new Date(row.startTime).getTime()
      ) {
        //已过期
        return 16;
      } else if (
        row.status == 11 &&
        new Date().getTime() > new Date(row.endTime).getTime()
      ) {
        //已结束
        return 17;
      } else {
        return row.status;
      }
    },
    getUuid() {
      var s = [];
      var hexDigits = "0123456789abcdef";
      for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
      s[8] = s[13] = s[18] = s[23] = "-";

      var uuid = s.join("");
      return uuid;
    },
    //使用渠道选中时触发
    channelChange(callback) {
      let deptNodeList = [];
      let deptIds = [];
      if (this.deptType == 0) {
        deptNodeList = this.$refs.channelTree.getCheckedNodes();
        deptIds = deptNodeList.map((item, index) => {
          return item.deptId;
        });
        if (deptIds.indexOf("179") == -1) {
          deptIds.unshift("179");
          deptNodeList.unshift({
            deptId: 179,
            childName: "卡奥斯运营中心",
            id: 179,
          });
        }
      } else {
        //查询子平台信息
        let deptId = localStorage.getItem("deptId");
        deptIds.push(deptId);
        let userInfo = JSON.parse(localStorage.getItem("user"));
        deptNodeList.push({
          deptId: userInfo.deptId,
          childName: userInfo.deptName,
          id: userInfo.businessId,
        });
      }

      this.utils.request.listMemberGradeForMarket(
        {
          deptIds: deptIds.join(","),
        },
        (res) => {
          if (res.code == "0000") {
            let levelList = res.data;
            let restLevelInfo = [];
            //如果存在排除重新赋值
            this.memberGradeList.forEach((levelItem) => {
              let levelInfo = levelList.find(function (level) {
                return levelItem.deptId == level.deptId;
              });
              if (levelInfo != undefined) {
                restLevelInfo.push(levelItem);
              }
            });
            //遍历
            this.memberGradeList = restLevelInfo;
            for (let deptInfo of deptNodeList) {
              let levelItem = this.memberGradeList.find(function (level) {
                return deptInfo.deptId == level.deptId;
              });
              if (levelItem != undefined) {
                continue;
              }
              //如果不勾选子平台 删除已有子平台

              let levelInfo = levelList.find(function (level) {
                return level.deptId == deptInfo.deptId;
              });
              if (levelInfo == undefined) {
                this.memberGradeList.push({
                  deptId: deptInfo.deptId,
                  childName: deptInfo.childName,
                  businessId: deptInfo.id,
                  checkAll: true,
                  isIndeterminate: false,
                  levelSelectList: [],
                  levelList: [],
                });
              } else {
                //添加数据
                let selectLevelIds = levelInfo.mememberGradeResponseList.map(
                  (item, index) => {
                    return item.id;
                  }
                );
                levelInfo.mememberGradeResponseList.forEach((item) => {
                  item.key = this.getUuid();
                });
                this.memberGradeList.push({
                  deptId: deptInfo.deptId,
                  childName: deptInfo.childName,
                  businessId: deptInfo.id,
                  levelSelectList: selectLevelIds,
                  checkAll: true,
                  isIndeterminate: false,
                  levelList: levelInfo.mememberGradeResponseList,
                });
              }
            }
          } else {
            this.memberGradeList = [];
          }
          this.$nextTick(() => {
            if (callback != undefined) {
              callback();
            }
          });
        }
      );
      // this.getMemLevelList(deptIds.join(","))
    },

    //会员类型
    handleCheckAllMemTypeChange(val) {
      this.selectMemTypes = val ? [1, 2,3] : [];
      this.memTypeIsIndeterminate = false;
    },
    handleCheckedMemTypeChange(value) {
      let checkedCount = value.length;
      this.memTypeCheckAll = checkedCount === 3;
      this.memTypeIsIndeterminate = checkedCount > 0 && checkedCount < 3;
    },
    //渠道
      handleCheckAllChannelIdChange(val) {
        this.channelId = val ? [1,2,3] : [];
        this.channelIdIsIndeterminate = false;
      },
      handleCheckedChannelIdChange(value) {
        let checkedCount = value.length;
        this.channelIdCheckAll = checkedCount === 3;
        this.channelIdIsIndeterminate = checkedCount > 0 && checkedCount < 3;
      },

    //会员等级
    handleMemLevelCheckAllChange(index, checked) {
      if (!checked) {
        //取消全部
        let memberSelectGrade = this.memberGradeList[index];
        memberSelectGrade.checkAll = false;
        memberSelectGrade.isIndeterminate = false;
        memberSelectGrade.levelSelectList = [];
        // this.$s
        this.$set(this.memberGradeList, index, memberSelectGrade);
      } else {
        //选中全部
        let ids = [];
        this.memberGradeList[index].levelList.forEach((item) => {
          ids.push(item.id);
        });
        let memberSelectGrade = this.memberGradeList[index];
        memberSelectGrade.checkAll = true;
        memberSelectGrade.isIndeterminate = false;
        memberSelectGrade.levelSelectList = ids;
        // this.$s
        this.$set(this.memberGradeList, index, memberSelectGrade);
      }
    },
    memLevelChange(index, levelList) {
      //查看当前子平台是否全选
      let levelSelectList = this.memberGradeList[index].levelSelectList;
      if (levelSelectList == null || levelSelectList.length < 1) {
        //没有选中子级
        let memberSelectGrade = this.memberGradeList[index];
        memberSelectGrade.checkAll = false;
        memberSelectGrade.isIndeterminate = false;
        memberSelectGrade.levelSelectList = [];
        // this.$s
        this.$set(this.memberGradeList, index, memberSelectGrade);
        return;
      }
      let noSelectIds = [];
      levelList.forEach((item) => {
        if (levelSelectList.indexOf(item.id) == -1) {
          //存在
          noSelectIds.push(item.id);
        }
      });

      if (noSelectIds.length < 1) {
        //全选
        let ids = [];
        this.memberGradeList[index].levelList.forEach((item) => {
          ids.push(item.id);
        });
        let memberSelectGrade = this.memberGradeList[index];
        memberSelectGrade.checkAll = true;
        memberSelectGrade.isIndeterminate = false;
        memberSelectGrade.levelSelectList = ids;
        this.$set(this.memberGradeList, index, memberSelectGrade);
      } else {
        //没有全选
        let ids = [];
        let memberSelectGrade = this.memberGradeList[index];
        memberSelectGrade.checkAll = false;
        memberSelectGrade.isIndeterminate = true;
        this.$set(this.memberGradeList, index, memberSelectGrade);
      }
    },

    /**
     * 重置商品搜索
     */
    resetStaticGoodsSearch() {
      if (this.$refs["queryGoodsReuqest"] != undefined) {
        this.$refs["queryGoodsReuqest"].resetFields();
      }
      this.goodsStaticDataForm.start = 1;
      this.goodsStaticDataForm.limit = 10;
      this.skillQueryGoods();
    },
    handleCheckedAllProductChange(value) {
      this.isIndeterminateProductCheck = false;

      this.allProductData.forEach((f) => {
        f.isCheck = value;
        f.isIndeterminateCheck = false;
      });
    },
    handleCheckedProductChange(row, checked) {
      if (row.isIndeterminateCheck) {
        row.isCheck = true;
        checked = true;
      }
      row.isIndeterminateCheck = false;

      changeChild(row, checked);
      changeParent(row, this.allProductData);

      this.isAllProductChecked = this.allProductData.every((e) => {
        return e.isCheck;
      });

      this.isIndeterminateProductCheck =
        !this.isAllProductChecked &&
        this.allProductData.some((e) => {
          return e.isCheck;
        });
    },
    /**
     * 状态格式化
     */
    statusFormat(row) {
      if (
        row.status == 1 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //待提交
        return 11;
      } else if (
        row.status == 2 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //待审核
        return 12;
      } else if (
        row.status == 11 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //未开始
        return 13;
      } else if (
        row.status == 4 &&
        new Date().getTime() <= new Date(row.startTime).getTime()
      ) {
        //审核未通过
        return 14;
      } else if (
        row.status == 11 &&
        new Date().getTime() >= new Date(row.startTime).getTime() &&
        new Date().getTime() <= new Date(row.endTime).getTime()
      ) {
        //进行中
        return 15;
      } else if (
        (row.status == 1 || row.status == 2 || row.status == 4) &&
        new Date().getTime() > new Date(row.startTime).getTime()
      ) {
        //已过期
        return 16;
      } else if (
        row.status == 11 &&
        new Date().getTime() > new Date(row.endTime).getTime()
      ) {
        //已结束
        return 17;
      }
    },
    /**
     * 重置商家页面搜索
     */
    resetStaticStoreSearch() {
      if (this.$refs["storeStaticDataForm"] != undefined) {
        this.$refs["storeStaticDataForm"].resetFields();
      }
      this.storeStaticDataForm.start = 1;
      this.storeStaticDataForm.limit = 10;
      this.skillQueryStore();
    },
    /**
     * 重置商家页面搜索
     */
    resetMerchantSearch() {
      if (this.$refs["merchantStaticDataForm"] != undefined) {
        this.$refs["merchantStaticDataForm"].resetFields();
      }
      this.merchantStaticDataForm.start = 1;
      this.merchantStaticDataForm.limit = 10;
      this.skillQueryMerchant();
    },
    //金额抵扣类型 监听
    amountDeductTypeChange(val) {
      if (val != "0") {
        this.$set(this.dataForm, "useTotalAmountLimit", null);
        this.dataFormRules.useTotalAmountLimit[0].required = false;
      } else {
        this.dataFormRules.useTotalAmountLimit[0].required = true;
      }
    },
    //优惠方式联动
    changeCouponMode(data) {
      //金额
      if (data == 0) {
        this.promotionMethod = true;
        this.discountMethod = false;
      } else if (data == 1) {
        this.promotionMethod = false;
        this.discountMethod = true;
      }
    },
    /**
     * 清空店铺输入框
     */
    restStoreForm() {

      this.$set(this.storeDataForm, "storeCode", null);
      this.$set(this.storeDataForm, "storeName", null);
      this.$set(this.storeDataForm, "storeType", null);
      this.$set(this.storeDataForm, "merchantName", null);
      this.$set(this.storeDataForm, "start", 1);
      this.queryPageStoreList();
    },
    /**
     * 清空商品输入框
     */
    restProductForm() {

      this.$set(this.formInline, "goodsName", null);
      this.$set(this.formInline, "goodsCategory", null);
      this.$set(this.formInline, "thirdSpuId", null);
      this.$set(this.formInline, "storeName", null);
      this.$set(this.formInline, "start", 1);
      this.queryPageProductManagement();
    },
    /**
     * channelIdsChange
     */
    channelIdsChange(val, checkedKeys) {
      this.$set(this.dataForm, "channelIds", checkedKeys.checkedKeys);
      this.channelChange();
    },
    /**
     * 添加全部商品
     */
    saveAllGoods() {
      // const loading = this.$loading({
      //   lock: true,
      //   text: "小的正在加载中,请稍后...",
      //   spinner: "el-icon-loading",
      //   background: "rgba(0, 0, 0, 0.7)"
      // });
      this.utils.request.couponAddAllGoods(
        {
          promotionId: this.promotionId,
        },
        (res) => {
          // loading.close();
          this.goodsCurrentChange(1);
        }
      );
    },
    /**
     * 商品页分页
     */
    goodsSizeChange() {},
    goodsCurrentChange(val) {
      this.goodsStaticDataForm.start = val;
      this.skillQueryGoods();
    },
    /**
     * 商家页分页
     */
    merchantSizeChange() {},
    merchantCurrentChange(val) {
      this.merchantStaticDataForm.start = val;
      this.skillQueryMerchant();
    },
    /**
     * 店铺
     */
    storeSizeChange() {},
    storeCurrentChange(val) {
      this.storeStaticDataForm.start = val;
      this.skillQueryStore();
    },
    /**
     * 清空商家搜索框
     */
    restMerchantForm() {

      this.$set(this.merchantDataForm, "orgNumber", null);
      this.$set(this.merchantDataForm, "name", null);
      this.$set(this.merchantDataForm, "merchantType", null);
      this.$set(this.merchantDataForm, "start", 1);
      this.queryPageMerchantList();
    },
    /**
     * 弹窗条件查询商家
     */
    queryPageMerchantManagement() {
      this.merchantDataForm.start = 1;
      this.queryPageMerchantList();
    },
    /**
     * 保存模板
     */
    saveTemplate() {
      var that = this;
      this.templateForm.promotionId = this.promotionId;
      if (
        this.templateForm.templateName == null ||
        this.templateForm.templateName == ""
      ) {
        that.$message({
          message: "模板名称不能为空",
          type: "error",
        });
        return false;
      }
      // const loading = this.$loading({
      //   lock: true,
      //   text: "小的正在加载中,请稍后...",
      //   spinner: "el-icon-loading",
      //   background: "rgba(0, 0, 0, 0.7)"
      // });
      this.utils.request.couponSaveTemplate(this.templateForm, (res) => {
        // loading.close();
        if (res.code == "0000") {
          this.$message({
            message: "保存成功",
            type: "success",
          });
          this.templateDialogFormVisible = false;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },

    //新老用户
    handleCheckAllChange2(val) {
      this.dataForm.proUserType = val
        ? proUserTypeRadio.map(function (value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate2 = false;
    },
    handleCheckedCitiesChange2(value) {
      let checkedCount = value.length;
      this.checkAll2 = checkedCount === this.proUserTypeRadios.length;
      this.isIndeterminate2 =
        checkedCount > 0 && checkedCount < this.proUserTypeRadios.length;
    },

    promotionIdSet(val) {
      this.promotionId = val.promotionId;
    },
    /**
     * 查询触发场景
     */
    queryTriggerList() {
      //查询触发场景
      this.utils.request.couponQueryTrigger(
        {
          promotionId: this.promotionId,
        },
        (res) => {
          if (res != null && res.data != null) {
            this.triggerSceneForm.triggerNum = res.data.triggerNum;
            let triggerType = res.data.triggerType;
            if (triggerType != null && triggerType.length > 0) {
              this.$set(this.triggerSceneForm, "userRegistered", false);
              this.$set(this.triggerSceneForm, "userDetail", false);
              this.$set(this.triggerSceneForm, "sign", false);
              this.$set(this.triggerSceneForm, "favorite", false);
              this.$set(this.triggerSceneForm, "lottery", false);
            }
            triggerType.forEach((trigger) => {
              let triggerIds = trigger.split(",");
              triggerIds.forEach((item) => {
                if (item == "00") {
                  this.$set(this.triggerSceneForm, "pageTrigger", true);
                  this.$set(this.triggerSceneForm, "triggerType", "1");
                } else if (item == "10") {
                  this.$set(this.triggerSceneForm, "userRegistered", true);
                  this.$set(this.triggerSceneForm, "triggerType", "3");
                } else if (item == "11") {
                  this.$set(this.triggerSceneForm, "userDetail", true);
                  this.$set(this.triggerSceneForm, "triggerType", "3");
                } else if (item == "31") {
                  this.$set(this.triggerSceneForm, "sign", true);
                  this.$set(this.triggerSceneForm, "triggerType", "3");
                } else if (item == "32") {
                  this.$set(this.triggerSceneForm, "favorite", true);
                  this.$set(this.triggerSceneForm, "triggerType", "3");
                } else if (item == "33") {
                  this.$set(this.triggerSceneForm, "lottery", true);
                  this.$set(this.triggerSceneForm, "triggerType", "3");
                } else if (item == "40") {
                  this.$set(this.triggerSceneForm, "triggerType", "2");
                }
              });
              //TODo
            });

            this.utils.request.patchGrouponThemeQueryListByIds(
              {
                ids: res.data.patchGroupTriggerList,
              },
              (result) => {
                if (result.code == "0000") {
                  this.patchGrouponTableData = result.data;
                }
              }
            );
            this.utils.request.skillQueryConfigList(
              {
                promotionIdList: res.data.speedKillTriggerList,
              },
              (result) => {
                if (result.code == "0000") {
                  this.skillTableData = result.data;
                }
              }
            );
          }
        }
      );
    },
    /**
     * 确认添加活动
     */
    addTriggerChange() {
      if (this.triggerActiveName == "1") {
        //拼团
        if (this.triggerSelectData.length < 1) {
          this.$message({
            message: "请选择要添加的活动",
            type: "error",
          });
          return false;
        }
        this.patchGrouponTableData = this.triggerSelectData;
        this.triggerSelectData = [];
      } else {
        //秒杀
        if (this.triggerSelectData.length < 1) {
          this.$message({
            message: "请选择要添加的活动",
            type: "error",
          });
          return false;
        }
        this.skillTableData = this.triggerSelectData;
        this.triggerSelectData = [];
      }
      this.triggerVisible = false;
    },
    /**
     * 选择活动
     */
    addTriggerChangeSelect(val) {
      this.triggerSelectData = val;
    },
    /**
     * 查询活动列表
     */
    queryPageTriggerManagement() {},
    /**
     * 条数刷新
     */
    triggerhandleSizeChange(val) {},
    /**
     * 换页刷新
     */
    triggerhandleCurrentChange(val) {
      this.$refs["triggerDataForm"].validate((valid) => {
        if (valid) {
          this.triggerDataForm.start = val;
          if (this.triggerActiveName == "1") {
            //拼团
            this.queryGrouponPage();
          } else {
            //秒杀
            this.querySkillPage();
          }
        }
      });
    },
    /**
     * 添加活动
     */
    addTrigger() {
      this.triggerVisible = true;
      this.triggerAddTableData = [];
      //查询活动列表
      if (this.triggerActiveName == "1") {
        //拼团
        this.queryGrouponPage();
      } else {
        //秒杀
        this.querySkillPage();
      }
    },
    /**
     * 查询秒杀活动
     */
    querySkillPage() {
      this.triggerDataForm.promType = 4;
      this.triggerDataForm["pageNo"] = this.triggerDataForm.start;
      this.triggerDataForm["pageSize"] = this.triggerDataForm.limit;
      // this.utils.request.skillQueryConfigPage(this.triggerDataForm, res => {
      //   this.triggerAddTableData = res.data.rows;
      //   this.triggerListTotal = res.data.total;
      // });
      let this_ = this;
      this.utils.request.promotionList(this.triggerDataForm, function (res) {
        if (res.code == "0000") {
          this_.triggerAddTableData = res.data.list;
          this_.triggerListTotal = res.data.totalCount;
        }
      });
    },
    /**
     * 查询拼团活动
     */
    queryGrouponPage() {
      this.triggerDataForm.promType = null;
      this.triggerDataForm["pageNo"] = this.triggerDataForm["start"];
      this.triggerDataForm["pageSize"] = this.triggerDataForm["limit"];
      this.utils.request.grouponQueryPage(this.triggerDataForm, (res) => {
        this.triggerAddTableData = res.data.list;
        this.triggerListTotal = res.data.totalCount;
      });
    },
    /**
     * 删除限制
     */
    deleteTrigger(index, row) {
      if (this.triggerActiveName == "1") {
        //拼团
        this.patchGrouponTableData.splice(index, 1);
      } else {
        this.skillTableData.splice(index, 1);
      }
    },
    /**
     * 活动发放tabs切换
     */
    triggerActiveClick(val) {
      this.$set(this.triggerDataForm, "id", "");
      this.$set(this.triggerDataForm, "promotionId", "");
      this.$set(this.triggerDataForm, "promName", "");
    },
    /**
     * 确认添加商品
     */
    addProductChange(val) {
      if (this.selectAddProduct.length < 1) {
        this.$message({
          message: "请选择要添加的商品",
          type: "warning",
        });
        return false;
      }
      this.productTableData.forEach((res) => {
        this.selectAddProduct.forEach((item, index) => {
          //排除已保存过的商品
          if (res.goodsId == item.id) {
            this.selectAddProduct.splice(index, 1);
          }
        });
      });
      if (this.selectAddProduct && this.selectAddProduct.length > 0) {
        this.productTableData = this.productTableData.concat(
          this.selectAddProduct
        );
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
        this.relatedProducts();
      } else {
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
      }
    },
    /* 关联商品 */
    relatedProducts() {
      //this.active = this.active + 1;
      if (this.productTableData.length < 1) {
        this.$message({
          message: "所关联的商品不能为空",
          type: "warning",
        });
        return false;
      }
      // const loading = this.$loading({
      //   lock: true,
      //   text: "小的正在努力加载中......",
      //   spinner: "el-icon-loading",
      //   background: "rgba(0, 0, 0, 0.8)"
      // });
      let that = this;
      let param = this.selectAddProduct.map((item) => item.id);
      this.utils.request.couponAddGoods(
        {
          promotionId: this.promotionId,
          goodsInfoList: param,
        },
        (res) => {
          // loading.close();
          if (res != null && res.data != null && res.code == "0000") {
            //商品新增成功
            that.skillQueryGoods();
            that.selectAddProduct = [];
          }
        }
      );
    },
    /**
     * 查询绑定的商品
     */
    skillQueryGoods(index) {
      // let that = this;
      // this.goodsStaticDataForm.promotionId = this.promotionId;
      // that.utils.request.couponQueryGoods(this.goodsStaticDataForm, data => {
      //   if (data != null) {
      //     that.productTableData = data.data.goodsInfoList;
      //     that.allProductData = getAllRow(that.productTableData, []);
      //     this.goodsTotal = Number(data.data.total);
      //     this.skuTotal = Number(data.data.skuTotal);
      //     this.isIndeterminateProductCheck = false;
      //     this.isAllProductChecked = false;
      //   }
      // });
      let that = this;
      this.goodsStaticDataForm.promotionId = this.promotionId;
      this.goodsStaticDataForm.queryGoodsReuqest = this.queryGoodsReuqest;
      that.utils.request.queryRedGoodsByPromotionId(
        this.goodsStaticDataForm,
        (data) => {
          if (data != null) {
            if (data.data.goodsInfoList == null) {
              that.productTableData = [];
              this.goodsTotal = Number(0);
              this.skuTotal = Number(0);
              this.isIndeterminateProductCheck = false;
              this.isAllProductChecked = false;
            } else {
              that.productTableData = data.data.goodsInfoList;
              // this.allProductData = this.productTableData;
              that.allProductData = getAllRow(that.productTableData, []);
              this.goodsTotal = Number(data.data.total);
              this.skuTotal = Number(data.data.skuTotal);
              this.isIndeterminateProductCheck = false;
              this.isAllProductChecked = false;
            }
          }
        }
      );
    },
    selectPorduct(val) {
      this.productSelectFlag = val;
    },
    /**
     * 条数刷新
     */
    producthandleSizeChange(val) {},
    /**
     * 换页刷新
     */
    producthandleCurrentChange(val) {
      this.formInline.start = val;
      this.queryPageProductManagement();
    },
    /**
     * 选择商品
     */
    selectAddProductChange(val) {
      this.selectAddProduct = val;
    },
    /**
     * 批量删除商品
     */
    batchDeleteProduct() {
      /*let ids = [];
      this.allProductData.forEach(function (item, index, array) {
        //判断父下面是否全选
        if (item.mpParentId == null && item.isCheck) {
          if (item.children && item.children.length > 0) {
            let isCheckItems = item.children.filter(function (subItem, index) {
              return !subItem.isCheck;
            });
            if (!(isCheckItems && isCheckItems.length > 0)) {
              ids.push(item.goodsId);
            }
          } else {
            ids.push(item.goodsId);
          }
        } else if (item.mpParentId != null && item.isCheck) {
          ids.push(item.goodsId);
        }
      });
      if (ids.length < 1) {
        this.$message({
          message: "请选择要删除的商品",
          type: "warning",
        });
        return false;
      }*/
      var this_=this;
      if (this.productSelectFlag.length < 1) {
        this.$message({
          message: "请选择要删除的商品",
          type: "warning",
        });
        return false;
      }
      this.$confirm("确认批量删除已选内容？", "提示", {
        type: "warning",
        closeOnClickModal: false,
      })
        .then(() => {
          this.productSelectFlag.forEach((item) => {
            this_.utils.request.couponDeleteGoods(
              {
                promotionId: this_.promotionId,
                goodsId: item.goodsId,
              },
              (res) => {
                //查询表单
                this_.skillQueryGoods();
              }
            );
          });
            this_.productSelectFlag = [];
        })
        .catch(() => {});
    },
    deleteProduct(index, row) {
      let proId = row.goodsId;
      this.utils.request.couponDeleteGoods(
        {
          promotionId: this.promotionId,
          goodsId: proId,
        },
        (res) => {
          this.skillQueryGoods();
        }
      );
    },
    /**
     * 弹窗选择店铺
     */
    addStoreChangeSelect(val) {
      this.addStoreSelect = val;
    },
    /**
     * 弹窗换页刷新
     */
    storehandleSizeChange(val) {
      this.storeDataForm.limit = val;
      this.queryPageStoreList();
    },
    /**
     * 弹窗翻页
     */
    storehandleCurrentChange(val) {
      this.storeDataForm.start = val;
      this.queryPageStoreList();
    },
    /**
     * 查询关联
     */
    skillQueryMerchant() {
      let that = this;
      this.merchantStaticDataForm.promotionId = this.promotionId;
      this.utils.request.couponQueryMerchant(
        this.merchantStaticDataForm,
        (res) => {
          if (res != null && res.data != null) {
            this.merchantStaticTableData =
              res.data.merchantInfoList == null
                ? []
                : res.data.merchantInfoList;
            let data = [];
            this.merchantStaticTableData.forEach((item) => {
              data.push({
                orgNumber: item.orgNumber,
                id: item.merchantId,
                name: item.merchantName,
                merchantType: item.merchantTypeId,
              });
            });
            this.merchantStaticTableData = data;
            this.merchantTotal = Number(res.data.total);
          }
        }
      );
    },
    /**
     * 查询关联的店铺
     */
    skillQueryStore() {
      let that = this;
      this.storeStaticDataForm.promotionId = this.promotionId;
      this.utils.request.couponQueryStore(this.storeStaticDataForm, (res) => {
        if (res != null && res.data != null) {
          this.storeTableData =
            res.data.storeInfoList == null ? [] : res.data.storeInfoList;
          let data = [];
          this.storeTableData.forEach((item) => {
            data.push({
              id: item.storeId,
              storeName: item.storeName,
              storeCode: item.storeCode,
              merchantId: item.merchantId,
              merchantName: item.merchantName,
              storeType: item.storeType,
            });
          });
          this.storeTableData = data;
          this.storeTotal = Number(res.data.total);
        }
      });
    },
    /**
     * 确认添加店铺
     */
    addStoreChange() {
      if (this.addStoreSelect.length < 1) {
        this.$message({
          message: "请选择要添加的店铺",
          type: "warning",
        });
        return false;
      }
      this.storeTableData.forEach((res) => {
        this.addStoreSelect.forEach((item, index) => {
          //排除已保存过的店铺
          if (res.id == item.id) {
            this.addStoreSelect.splice(index, 1);
          }
        });
      });
      if (this.addStoreSelect && this.addStoreSelect.length > 0) {
        let that = this;
        let paramData = [];
        this.addStoreSelect.forEach((item) => {
          paramData.push({
            merchantId: item.merchantId,
            storeName: item.storeName,
            storeId: item.id,
            storeCode: item.storeCode,
            // "storeId":item.id,
            channelCode: "",
          });
        });
        let param = {
          promotionId: this.promotionId,
          storeInfoList: paramData,
        };
        this.utils.request.couponAddStore(param, (res) => {
          this.dialogVisibleStore = !this.dialogVisibleStore;
          this.addStoreSelect = [];
          this.skillQueryStore();
        });
      } else {
        this.dialogVisibleStore = !this.dialogVisibleStore;
      }
    },
    /**
         添加店铺
         */
    addStore() {
      // ;
      if (this.merchantStaticTableData.length == 0) {
        this.$message({
          message: "请先选择商家",
          type: "error",
        });
        return false;
      }
      this.queryPageStoreList();
      this.dialogVisibleStore = true;
    },
    /**
     * 批量删除店铺
     */
    batchDeleteStore() {
      if (this.multipleStoreSelection.length < 1) {
        this.$message({
          message: "请选择要删除的店铺",
          type: "warning",
        });
        return false;
      }
      this.$confirm("确认批量删除已选内容？", "提示", {
        type: "warning",
        closeOnClickModal: false,
      })
        .then(() => {
          this.multipleStoreSelection.forEach((item) => {
            for (let index = 0; index < this.storeTableData.length; index++) {
              if (this.storeTableData[index].id == item.id) {
                this.storeTableData.splice(index, 1);
              }
              this.utils.request.couponDeleteStore(
                {
                  promotionId: this.promotionId,
                  storeId: item.id,
                },
                (res) => {}
              );
            }
          });
          this.multipleStoreSelection = [];
        })
        .catch(() => {});
    },
    /**
     * 选择店铺
     */
    selectStoreChange(val) {
      this.multipleStoreSelection = val;
    },

    /**
     * 添加商家
     */
    addMerchantChange() {
      if (this.addMerchantSelect.length < 1) {
        this.$message({
          message: "请选择要添加的商家",
          type: "warning",
        });
        return false;
      }
      this.merchantStaticTableData.forEach((res) => {
        this.addMerchantSelect.forEach((item, index) => {
          //排除已选择的商家
          if (res.id == item.id) {
            this.addMerchantSelect.splice(index, 1);
          }
        });
      });
      if (this.addMerchantSelect && this.addMerchantSelect.length > 0) {
        // this.tableData.push(row);
        this.tableData = this.tableData.concat(this.addMerchantSelect);
        let that = this;
        let paramData = [];
        this.addMerchantSelect.forEach((item) => {
          paramData.push({
            orgNumber: item.orgNumber,
            merchantId: item.id,
            merchantName: item.name,
            merchantTypeId: item.merchantType,
            merchantTypeName:
              item.merchantType == "1" ? "自营商家" : "第三方商家",
            channelCode: "",
          });
        });
        let param = {
          promotionId: this.promotionId,
          merchantInfoList: paramData,
        };
        this.utils.request.couponAddMerchant(param, (res) => {
          this.dialogVisibleMerchant = !this.dialogVisibleMerchant;
          this.addMerchantSelect = [];
          this.skillQueryMerchant();
        });
      } else {
        this.dialogVisibleMerchant = !this.dialogVisibleMerchant;
      }
    },
    /**
     * 新增商家选择
     */
    addMerchantChangeSelect(val) {
      this.addMerchantSelect = val;
    },
    /**
     * 商家列表换页刷薰
     *
     */
    merchanthandleSizeChange(val) {
      this.merchantDataForm.limit = val;
      this.queryPageMerchantList();
    },
    merchanthandleCurrentChange(val) {
      this.merchantDataForm.start = val;
      this.queryPageMerchantList();
    },

    restForm() {
      this.$refs["triggerDataForm"].resetFields();
      this.$set(this.triggerDataForm, "start", 1);
      this.$set(this.triggerDataForm, "limit", 10);
      if (this.triggerActiveName == "1") {
        //拼团
        this.queryGrouponPage();
      } else {
        //秒杀
        this.querySkillPage();
      }
    },
    queryPageProductManagement() {
      let that = this;
      this.productListloading = true;
      // ;
      this.formInline.goodsCategory =
        this.formInline.goodsCategory == ""
          ? null
          : this.formInline.goodsCategory;
      this.formInline.goodsName =
        this.formInline.goodsName == "" ? null : this.formInline.goodsName;
      this.formInline.storeName == "" ? null : this.formInline.storeName;
      this.formInline.thirdSpuId == "" ? null : this.formInline.thirdSpuId;
      // this.formInline.storeIds = this.storeTableData.map(item=>item.id);
      this.utils.request.getCouponStoreIdsByPromotionId(
        {
          promotionId: this.promotionId,
        },
        (data) => {
          if (data.data == null && data.data.length < 1) {
            this.$message({
              message: "请选择店铺",
              type: "error",
            });
            this.active = this.active - 1;
            return false;
          }
          this.formInline.storeIds = data.data;
          this.utils.request.promotionSpuPageByPromotionId(
            this.formInline,
            (res) => {
              that.productListloading = false;
              if (res.code == "0000") {
                // that.tableDataTwo = res.data.rows;
                that.tableDataTwo = res.data.rows.map((ele, index) => {
                  let spu = {};
                  spu.id = ele.id;
                  spu.thirdSpuId = ele.code;
                  spu.goodsName = ele.chineseName;
                  // spu.totalStock = ele.totalStock;
                  spu.goodsCategory = ele.fullNamePath;
                  // spu.merchantName = ele.merchantName;
                  spu.storeName = ele.storeName;
                  spu.salePriceScope = ele.salePriceWithTax;
                  // spu.measureUnit = ele.measureUnit;
                  return spu;
                });
                that.productListTotal = res.data.total;
              }
            }
          );
        }
      );
    },
    /**
         添加店铺
         */
    addStore() {
      if (this.merchantStaticTableData.length == 0) {
        this.$message({
          message: "请先选择商家",
          type: "error",
        });
        return false;
      }
      this.queryPageStoreList();
      this.dialogVisibleStore = true;
    },
    queryPageStoreList() {
      this.utils.request.couponGetMerchantIdsByPromotionId(
        {
          promotionId: this.promotionId,
        },
        (data) => {
          if (data.data.length == 0) {
            this.$message({
              message: "请先选择商家",
              type: "success",
            });
            return false;
          }
          let this_ = this;
          this.storeDataForm.merchantIds = data.data.join(",");
          this.utils.request.sotreQueryByIds(this.storeDataForm, function (
            res
          ) {
            if (res.code == "0000") {
              this_.storeAddTableData = res.data.rows;
              this_.storeListTotal = Number(res.data.total);
            }
          });
        }
      );
    },
    /**
     * 批量删除店铺
     */
    // batchDeleteStore(){
    //     if(this.multipleStoreSelection.length < 1){
    //         this.$message({message:"请选择要删除的店铺",type:"warning"})
    //         return false;
    //     }
    //       this.$confirm("确定删除吗？", "提示", {
    //         type: "warning"
    //     }).then(() => {
    //         this.multipleStoreSelection.forEach(item=>{
    //             for(let index = 0 ; index < this.storeTableData.length ; index++){
    //                 if(this.storeTableData[index].id == item.id){
    //                     this.storeTableData.splice(index,1);
    //                 }

    //             }
    //         })
    //         this.multipleStoreSelection = [];
    //     }).catch(() => {});
    // },
    /**
     * 选择店铺
     */
    selectStoreChange(val) {
      this.multipleStoreSelection = val;
    },
    /**
     * 删除店铺
     */
    handleDeleteStore(index, row) {
      // this.$confirm("确定删除吗？", "提示", {
      //   type: "warning",
      //   closeOnClickModal: false,
      // }).then(() => {
      let proId = row.id;
      for (var i = 0; i < this.storeTableData.length; i++) {
        if (this.storeTableData[i].id == proId) {
          this.storeTableData.splice(i, 1);
          this.utils.request.couponDeleteStore(
            {
              promotionId: this.promotionId,
              storeId: proId,
            },
            (res) => {}
          );
        }
      }
      // })
    },

    /**
     * 添加商家按钮
     */
    addMerchant() {
      // this.queryPageProductManagement();
      this.queryPageMerchantList();
      this.dialogVisibleMerchant = true;
    },
    queryPageMerchantList() {
      let that = this;
      this.productListloading = true;
      //只有运营平台有使用渠道
      if (this.deptType == 0) {
        this.merchantDataForm.childIds = that.dataForm.channelIds;
      }
      this.utils.request.queryMerchantList(this.merchantDataForm, (res) => {
        that.productListloading = false;
        if (res.code == "0000") {
          that.merchantTableData = res.data.rows;
          that.merchantListTotal = res.data.total;
        }
      });
    },
    /**
     * 多选商家
     */
    selectMerchantChange(val) {
      this.multipleMerchantSelection = val;
    },
    handleDelete(index, row) {
      // this.$confirm("确定删除吗？", "提示", {
      //   type: "warning",
      //   closeOnClickModal: false,
      // }).then(() => {
      let proId = row.id;
      for (var i = 0; i < this.merchantStaticTableData.length; i++) {
        if (this.merchantStaticTableData[i].id == proId) {
          this.merchantStaticTableData.splice(i, 1);
          this.utils.request.couponDeleteMerchant(
            {
              merchantId: proId,
              promotionId: this.promotionId,
            },
            (res) => {
              this.merchantStaticDataForm.start = 1;
              this.storeStaticDataForm.start = 1;
              this.skillQueryMerchant();
              this.skillQueryStore();
            }
          );
        }
      }
      // })
    },
    /**
     * 批量删除商家
     */
    batchDeleteMerchant() {
      if (this.multipleMerchantSelection.length < 1) {
        this.$message({
          message: "请选择要删除的商家",
          type: "warning",
        });
        return false;
      }
      this.$confirm("确认批量删除已选内容？", "提示", {
        type: "warning",
        closeOnClickModal: false,
      })
        .then(() => {
          this.multipleMerchantSelection.forEach((item) => {
            for (
              let index = 0;
              index < this.merchantStaticTableData.length;
              index++
            ) {
              if (this.merchantStaticTableData[index].id == item.id) {
                this.merchantStaticTableData.splice(index, 1);
              }
              this.utils.request.couponDeleteMerchant(
                {
                  merchantId: item.id,
                  promotionId: this.promotionId,
                },
                (res) => {
                  //查询商家 查询店铺
                  this.merchantStaticDataForm.start = 1;
                  this.storeStaticDataForm.start = 1;
                  this.skillQueryMerchant();
                  this.skillQueryStore();
                }
              );
            }
          });
          this.multipleMerchantSelection = [];
          //TODO 删除商家
        })
        .catch(() => {});
    },
    /**
     * 渠道选择
     */
    channelCheckChange(data, checked, indeterminate) {
      let index = this.dataForm.channelIds.indexOf(data.id);
      if (index != -1) {
        //存在
        this.dataForm.channelIds.splice(index, 1);
      } else {
        //不存在
        this.dataForm.channelIds.push(data.id);
      }
    },

    start_time(e) {
      this.dataForm.couponUseStartTime = formatDate(
        e[0],
        "yyyy-MM-dd hh:mm:ss"
      );
      this.dataForm.couponUseEndTime = formatDate(e[1], "yyyy-MM-dd hh:mm:ss");
    },
    activityTime(e) {
      this.dataForm.startTime = formatDate(e[0], "yyyy-MM-dd hh:mm:ss");
      this.dataForm.endTime = formatDate(e[1], "yyyy-MM-dd hh:mm:ss");
    },
    select(row) {
      let flag = true;
      this.tableData.forEach((res) => {
        if (res.id == row.id) {
          this.$message({
            message: "不能添加重复商品",
            type: "error",
          });
          flag = false;
        }
      });
      if (flag) {
        this.tableData.push(row);
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
      }
    },
    handleChange(myArray) {},
    add() {
      this.queryPageProductManagement();
      this.dialogVisibleTwo = true;
    },
    //table的双色条纹
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    //修改table header的背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color:rgb(250,250,250);";
      }
    },
    //table的编辑和删除
    handleEdit(index, row) {
      row.disabled = !row.disabled;
    },
    handleRemove(file, fileList) {},
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    next() {

      if (this.active == 1) {
        //提交订单
        this.submitCouponInfo("dataForm");
      } else if (this.active == 2) {
        //关联商家
        // this.relatedProducts();
        if (this.merchantStaticTableData.length == 0) {
          this.$message({
            message: "未添加商家",
            type: "fail",
          });
          return;
        }
        if (this.storeTableData.length == 0) {
          this.$message({
            message: "未添加店铺",
            type: "fail",
          });
          return;
        }
        //保存完商家、店铺后清空本地商品信息，防止接口返回慢还展示商品信息
        this.productTableData = [];
        this.skillQueryGoods();
        this.addActive();
      } else if (this.active == 3) {
        //关联商品
        // this.relatedProducts();
        if (this.productTableData.length == 0) {
          this.$message({
            message: "添加商品",
            type: "fail",
          });
          return;
        }
        this.queryTriggerList();
        this.addActive();
      } else if (this.active == 4) {
        //触发场景 保存触发场景
        let param = {};
        param.promotionId = this.promotionId;
        param.triggerType = this.triggerSceneForm.triggerType;
        if (param.triggerType == "1") {
          param.pageTrigger =
            this.triggerSceneForm.pageTrigger == true ? "00" : "";
        } else if (param.triggerType == "3") {
          param.systemTrigger =
            this.triggerSceneForm.userRegistered == true ? "10" : "";
          param.systemTrigger =
            this.triggerSceneForm.userDetail == true
              ? param.systemTrigger + "," + "11"
              : param.systemTrigger + "";

          param.taskTrigger = this.triggerSceneForm.sign == true ? "31" : "";
          param.taskTrigger = this.triggerSceneForm.favorite == true ? param.taskTrigger + "," + "32" : param.taskTrigger + "";
          param.taskTrigger = this.triggerSceneForm.lottery == true  ? param.taskTrigger + "," + "33" : param.taskTrigger + "";

        } else if (param.triggerType == "2") {
          param.taskTrigger = "40";
        }
        //编辑data
        param.patchGroupTriggerList =
          this.patchGrouponTableData == null
            ? []
            : this.patchGrouponTableData.map((item) => item.id);
        param.speedKillTriggerList =
          this.skillTableData == null
            ? []
            : this.skillTableData.map((item) => item.id);
        param.triggerNum = this.triggerSceneForm.triggerNum;
        this.utils.request.couponUpdateTrigger(param, (res) => {
          //调用审核接口 改成待提交
          // if (this.dataForm.status == 9 || this.dataForm.status == 4 || this.dataForm.status == null) {
          this.utils.request.couponCheckCoupon(
            {
              promotionId: this.promotionId,
              updateStatus: "1",
            },
            (data) => {
              this.$set(this.dataForm, "status", 11);
              this.addActive();
            }
          );
          // }
        });
      }
    },
    addActive() {
      if (parseInt(this.active) === 1) {
        this.active = parseInt(this.active) + 2;
      } else {
        this.active = parseInt(this.active) + 1;
      }

      this.$router.push({
        params: {
          promotionId: this.promotionId,
          active: this.active,
        },
      });
      if (this.active > 5) {
        this.$router.push({
          path: "/pages/promotionManagement/CouponManagerList",
        });
      }
    },
    back() {
      if (parseInt(this.active) === 3) {
        this.active = parseInt(this.active) - 2;
      } else {
        this.active = parseInt(this.active) - 1;
      }
      this.$router.push({
        params: {
          promotionId: this.promotionId,
          active: this.active,
        },
      });
      this.nextOrBack();
    },
    viewList() {
      // this.$emit("viewList");
      this.$router.push("/pages/promotionManagement/CouponManagerList");
    },
    shenheHuodong(flag) {
      if (flag == 0) {
        //提交审核
        let that = this;
        this.$confirm("确认提交审核？", "提示", {
          type: "warning",
          closeOnClickModal: false,
        }).then(() => {
          this.utils.request.couponCheckCoupon(
            {
              promotionId: this.promotionId,
              updateStatus: "2",
            },
            (res) => {
              this.shenhe = 1;
              this.$set(this.dataForm, "status", 12);
              that.$message({
                message: "提交审核成功",
                type: "success",
              });
              that.couponQueryConfigByPromotionId();
            }
          );
        });
      } else {
        //审核
        this.dialogFormVisible = true;
      }
      // this.$message({ message: "操作成功", type: "success" });
    },
    change(e) {
      if (e.indexOf("全部") > -1) {
        this.dataForm.couponUsePersonType = [];
        this.dataForm.couponUsePersonType.push("0");
        this.dataForm.couponUsePersonType.push("1");
        this.dataForm.couponUsePersonType.push("2");
      }
    },
    dateFilter: function (input) {
      var d = new Date(input);
      var year = d.getFullYear();
      var month =
        d.getMonth() < 9 ? "0" + (d.getMonth() + 1) : "" + (d.getMonth() + 1);
      var day = d.getDate() < 10 ? "0" + d.getDate() : "" + d.getDate();
      var hour = d.getHours() < 10 ? "0" + d.getHours() : "" + d.getHours();
      var minutes =
        d.getMinutes() < 10 ? "0" + d.getMinutes() : "" + d.getMinutes();
      var seconds =
        d.getSeconds() < 10 ? "0" + d.getSeconds() : "" + d.getSeconds();
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    /* 提交优惠券信息 */
    submitCouponInfo(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //如分摊则校验分摊比例总和不能超过100
          if (this.dataForm.costAllocationFlag == "1") {
            if (
              Number(this.dataForm.parentAllocationScale || 0) +
                Number(this.dataForm.merchantAllocationScale || 0) !=
              100
            ) {
              this.$message({
                message: "分摊比例总和为100",
                type: "warning",
              });
              // loading.close();
              return false;
            }
          }
         
          this.dataForm.memTypes = this.selectMemTypes.join(",");
          this.dataForm.proUserType = this.selectUserType.join(",");
          this.dataForm.channelId = this.channelId.join(",");


          let that = this;
          if (this.promotionId == "0") {
            this.utils.request.couponAddConfig(this.dataForm, (res) => {
              // loading.close();
              if (res.code == "0000") {
                that.promotionId = res.data;
                // this.skillQueryMerchant();
                // this.skillQueryStore();
                this.addActive();
              } else {
                that.$message({
                  message: res.msg || "新增优惠券失败,请重试",
                  type: "error",
                });
              }
            });
          } else {
            //编辑
            this.dataForm.promotionId = this.promotionId;
            this.utils.request.couponUpdateConfig(this.dataForm, (res) => {
              // loading.close();
              if (res.code == "0000") {
                // this.skillQueryMerchant();
                // this.skillQueryStore();
                this.addActive();
              } else {
                that.$message({
                  message: res.msg || "新增优惠券失败,请重试",
                  type: "error",
                });
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    reviewDialog: function (data) {
      let that = this;
      this.form.promotionId = this.promotionId;
      this.form.updateStatus = data;
      if (data == 4) {
        this.$refs.form.validate((auditRemarkE) => {
          if (auditRemarkE) {
          } else {
            throw Error("");
          }
        });
      }
      that.utils.request.couponCheckCoupon(this.form, (res) => {
        if (res.code == "0000") {
          that.dialogFormVisible = false;
          that.$message({
            message: "审核完成",
            type: "success",
          });
          // that.findPage();
          that.shenhe = 2;
        } else {
          that.$message({
            message: "审核失败",
            type: "error",
          });
        }
        that.couponQueryConfigByPromotionId();
      });
    },
    initData: function () {
      this.dataForm.url = "jic-market/coupon/template/query-template";
      this.dataForm.templateId = this.temId;
      this.utils.request.httpUtils(this.dataForm, (res) => {
        if (res.code == "0000") {
          for (var key in res.data) {
            this.dataForm[key] = res.data[key].toString();
          }
          this.dataForm.activityTime[0] = res.data.activityStartTime;
          this.dataForm.activityTime[1] = res.data.activityEndTime;
          this.dataForm.proportion = res.data.costAllocationScore;
          this.dataForm.couponUseTime[0] = res.data.couponUseStartTime;
          this.dataForm.couponUseTime[1] = res.data.couponUseEndTime;
        } else {
          that.$message({
            message: "查询数据异常,请重试!",
            type: "error",
          });
        }
      });
    },
    defaultChecked(channel) {
      //判断是否是修改 如果是修改 不默认选中全部
      if (this.promotionId == null || this.promotionId == "0") {
        let ids = this.channelList[0].children.map((item) => item.id);
        ids.push(channel.id + "");
        this.$set(this.dataForm, "channelCodes", ids);
        this.$set(this.dataForm, "channelIds", ids);
        this.$nextTick(() => {
          this.$refs.channelTree.setCheckedKeys(ids);
        });
      }
    },
    couponQueryConfigByPromotionId() {
      //查询详情
      let that = this;
      this.utils.request.couponQueryConfigByPromotionId(
        {
          promotionId: this.promotionId,
        },
        (res) => {
          for (const key in res.data) {
            if (
              key == "merchantAllocationScale" ||
              key == "parentAllocationScale"
            ) {
              this.$set(
                this.dataForm,
                key,
                Number(res.data[key]) == 0 ? null : Number(res.data[key])
              );
            } else {
              this.$set(
                this.dataForm,
                key,
                res.data[key] == "0" ||
                  res.data[key] == null ||
                  res.data[key] == ""
                  ? null
                  : res.data[key] + ""
              );
            }
          }

          this.$set(that.dataForm, "couponMode", res.data["couponMode"] + "");
          this.$set(
            that.dataForm,
            "amountDeductType",
            res.data["amountDeductType"] + ""
          );
          this.$set(that.dataForm, "couponType", res.data["couponType"] + "");

          this.$set(that.dataForm, "status", this.statusFormat(res.data));

          this.$set(this.dataForm, "activityTime", [
            new Date(res.data["startTime"]),
            new Date(res.data["endTime"]),
          ]);
          this.$set(this.dataForm, "couponUseTime", [
            new Date(res.data["couponUseStartTime"]),
            new Date(res.data["couponUseEndTime"]),
          ]);

          this.$set(this.dataForm, "status", res.data["status"]);

          if (
            this.dataForm.idLimitNum != null &&
            this.dataForm.idLimitNum == "0"
          ) {
            this.$set(this.dataForm, "idLimitNum", null);
          }
          if (
            this.dataForm.idLimitDayNum != null &&
            this.dataForm.idLimitDayNum == "0"
          ) {
            this.$set(this.dataForm, "idLimitDayNum", null);
          }
          if (
            this.dataForm.grantTotalNum != null &&
            this.dataForm.grantTotalNum == "0"
          ) {
            this.$set(this.dataForm, "grantTotalNum", null);
          }
          if (
            res.data["label"] != 0 &&
            res.data["label"] != null &&
            res.data["label"] != ""
          ) {
            this.$set(that.dataForm, "label", Number(res.data["label"]));
          }

          let _this = this;
          let selectMemTypes = [];
          res.data.memTypes.split(",").forEach((item) => {
            selectMemTypes.push(Number(item));
          });
          _this.selectMemTypes = selectMemTypes;
          if (selectMemTypes.length < 3) {
            _this.memTypeIsIndeterminate = true;
            _this.memTypeCheckAll = false;
          }

          let selectUserType = [];
          res.data.proUserType.split(",").forEach((item) => {
            selectUserType.push(Number(item));
          });
          _this.selectUserType = selectUserType;
          if (selectUserType.length < 2) {
            _this.userTypeIsIndeterminate = true;
            _this.userTypeCheckAll = false;
          }
          //渠道
            let channelId = [];
            res.data.channelId.split(",").forEach(item=>{
              channelId.push(Number(item));
            });
            _this.channelId = channelId;
            if(channelId.length < 3){
              this.channelIdIsIndeterminate = true;
              this.channelIdCheckAll = false;this.channelId
            }


          // this.dataForm.proUserType = this.dataForm.proUserType.split(",");
        }
      );
    },
    nextOrBack() {
      //根据当前url中active参数判断执行第几步方法
      if (this.active) {
        // debugger
        if (parseInt(this.active) == 2) {
          this.$nextTick(() => {
            this.skillQueryMerchant();
            this.skillQueryStore();
          });
        } else if (parseInt(this.active) == 3) {
          this.$nextTick(() => {
            this.skillQueryGoods();
          });
        } else if (parseInt(this.active) == 4) {
          this.$nextTick(() => {
            this.queryTriggerList();
          });
        }
      }
    },
    budgetChange(){
      if(this.dataForm.budget == '' || this.dataForm.budget == null){
        if(this.dataForm.grantTotalNum && this.dataForm.couponAmount){
          this.dataForm.budget = this.dataForm.grantTotalNum * this.dataForm.couponAmount;
        }
      }
    },
    // 更新优惠券商品限制
    updateCouponLimit(row){
      if(!this.checkProductLimits(row)){
        return false;
      }
      let param = {
        goodsInfoList: [
          {
            goodsId: row.goodsId,
            stockLimit: row.stockLimit,
            orderLimit: row.orderLimit,
            individualLimit: row.individualLimit,
            goodsName: row.goodsName,
            id:row.id
          }
        ],
        promotionId: this.promotionId
      };
      this.utils.request.couponUpdateGoods(param, res => {});
    },
    //检验商品
     checkProductLimits(row){
        var reg = /^(?!0(\.0{1,2})?$)(\d(\.\d{1,2})?|10)$/;//0-10
        var priceReg = /^\d+\.?\d{0,2}$/; // 2位小数
        var regPos = /^[1-9]([0-9]*)$/; // 非负整数
        if(row.stockLimit && !regPos.test(row.stockLimit)){
          row.stockLimit = null;
          this.$message({ message: "活动库存只能输入正整数", type: "error" });
          return false;
        }
        if(row.individualLimit && !regPos.test(row.individualLimit)){
          row.individualLimit = null;
          this.$message({ message: "个人限购只能输入正整数", type: "error" });
          return false;
        }
        if(row.orderLimit && !regPos.test(row.orderLimit)){
          row.orderLimit = null;
          this.$message({ message: "订单限购只能输入正整数", type: "error" });
          return false;
        }
        if(Number(row.stockLimit) > Number(row.reserveNum)){
          row.stockLimit = null;
          this.$message({ message: "活动库存需小于等于店铺库存", type: "error" });
          return false;
        }
        if(Number(row.orderLimit) > Number(row.individualLimit)){
          row.orderLimit = null;
          this.$message({ message: "订单限购需小于于等于个人限购", type: "error" });
          return false;
        }
        return true;
    },
  },
  created() {
    this.promotionId = this.$route.params.promotionId;
    this.active = this.$route.params.active;
  },
  mounted() {
    if (this.promotionId != "0") {
      this.couponQueryConfigByPromotionId();
    }
    //根据当前url中active参数判断执行第几步方法
    this.nextOrBack();
  },
};
</script>

<style lang="scss" scoped>
@import "../../../assets/css/public.scss";

/deep/ .is-bordered {
  padding: 12px 20px 12px 10px;
}

.mleft10 {
  margin-right: 10px;
}

.desc2 {
  margin: 0 0 30px 140px;
}

.issueTime {
  /deep/ .el-input {
    width: auto !important;
  }
}

.flexBox {
  display: flex;
  flex-wrap: nowrap;
  align-content: flex-start;

  .child-name {
    flex-shrink: 0;
  }

  .checkboxes {
    display: flex;
  }
}

.pdl75 {
  padding-left: 75px;
}

.labelColor333 {
  /deep/ .el-form-item__label {
    color: #333 !important;
  }
}

// .el-checkbox{
//   width: 120px !important;
//   height: 30px !important;
//   padding: 6px 8px 5px !important;
//   /deep/ .el-checkbox__label{
//     padding-left: 8px !important;
//     font-size: 12px !important;
//     }
// }
// .el-checkbox.is-bordered+.el-checkbox.is-bordered{
//   margin-left: 0 !important;
// }

// .el-radio{
//   width: 120px !important;
//   height: 30px !important;
//   padding: 6px 8px 5px !important;
//   /deep/ .el-radio__label{
//     padding-left: 8px !important;
//     font-size: 12px !important;
//     }
// }
// .el-radio.is-bordered+.el-radio.is-bordered{
//   margin-left: 0 !important;
// }

.ml80 {
  margin-left: 80px !important;
}

.w310 {
  width: 310px;

  /deep/ .el-input__inner {
    width: 310px;
  }
}

.h32 {
  height: 32px;
}

.lh32 {
  line-height: 32px;
}

.w126 {
  width: 126px;
}

.oe {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.width100 {
  width: 97px;
}

.w104 {
  width: 104px;
}

.ml60 {
  margin-left: 60px;
}

.pdl30 {
  padding-left: 30px;
}

.pdt20 {
  padding-top: 20px;
}

.width450 {
  width: 450px !important;

  /deep/ .el-input__inner {
    width: 450px !important;
  }
}

.mt7 {
  margin-top: 7px;
}

.mb30 {
  margin-bottom: 30px !important;
}

.w130 {
  width: 130px !important;
}
</style>
